Selenium Flashcards

1
Q

Rules for id attribute:

A
  • must be unique in a HTML document
  • least one character
  • no spaces
  • case sensitive
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Ways to locate HTML elements on a web page:

A

Order of preference:

  • id
  • name (if unique)
  • class
  • CSS selector
  • XPath without text or indexing
  • Link text or partial link text
  • XPath with text or indexing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to locate HTML elements by name attribute:

A
  • ctr + F and type in the name of the element
  • Selenium WebDriver method, ex:
    browser=webdriver.Firefox()
    browser.get(“https://stackoverflow.com”)
    element = browser.find_element(By.NAME,”q”)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to locate HTML elements by id attribute:

A
  • ctr + F and type in the id

-Selenium WebDriver method, ex:
browser=webdriver.Firefox()
browser.get(“https://stackoverflow.com”)
element = browser.find_element(By.ID, “hiking”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to locate HTML elements by class attribute:

A
  • ctr + F and type in the class, preceded by “.”, ex: .vector-menu-heading

-Selenium WebDriver method, ex:
browser=webdriver.Firefox()
browser.get(“https://stackoverflow.com”)
element = browser.find_element(By.CLASS, “vector-menu-heading”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

The name attribute:

A
  • does not have to be unique

- is mostly used in forms to reference the element when data is submitted, e.g. login forms

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

XPath

A
  • stands for XML path language
  • uses path expressions to identify and navigate nodes in an XML document
  • can be used to select one or more nodes in the document using relative or absolute paths
  • used in worst case scenarios, like when a specific class, name, or id is unavailable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Absolute XPath

A
  • the complete path from the root to the desired element, ex: /html/body/form[1]
  • not as desirable to use as relative XPath
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Relative XPath

A
  • just references the desired element, ex: //form[1]

- preferred over absolute XPath

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to locate HTML element by XPath:

A

-Selenium WebDriver method, ex:
browser=webdriver.Firefox()
browser.get(“https://stackoverflow.com”)
element = browser.find_element(By.XPATH, “//form[1]”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

XPath Syntax: //

A

selects nodes in the document from the current node that match the selection no matter where they are

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

XPath Syntax: /

A

Selects from the root node

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

XPath Syntax: .

A

Selects the current node

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

XPath Syntax: ..

A

Selects the parent of the current node

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

XPath Syntax: @

A

Selects attributes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

XPath Syntax: nodename

A

Selects all nodes with the name “nodename”

17
Q

Class names

A

not unique

18
Q

What are waits?

A
  • Elements in a webpage may be loaded at different time intervals due to Ajax calls
  • Waiting adds a time interval between actions performed by WebDriver
19
Q

Explicit Waits

A
  • Stops execution until a certain condition is satisfied

- It’s good practice to use explicit waits before locating and interacting with elements

20
Q

Implicit Waits

A
  • Polls the DOM for a given amount of time while trying to locate an element
  • Differs from explicit waits by waiting before every call made by your script. Explicit waits wait for a specific condition to be fulfilled only.
21
Q

CSS Selectors: *

A

Universal selector: selects all elements. Optionally, it may be restricted to a specific namespace or to all namespaces

22
Q

CSS Selectors: elementname

A

Type selector: selects all elements that have the given node name.
Example: input will match any element with the name elementname

23
Q

CSS Selectors: .

A
Class selector: selects all elements that have the given class attribute. 
Example: .index will match any element that has a class of "index".
24
Q

CSS Selectors: #

A

id selector: selects an element based on the value of its id attribute. There should be only one element with a given ID in a document.

Example: #toc will match the element that has the ID “toc”.

25
Q

CSS Selectors: []

A

Selects all elements that have the given attribute.

Example: [autoplay] will match all elements that have the autoplay attribute set (to any value).

26
Q

How to locate elements by CSS Selectors:

A
  • ctrl + F and type in element with appropriate CSS selector (., *, [], etc)

-Selenium WebDriver method, ex:
browser=webdriver.Firefox()
browser.get(“https://stackoverflow.com”)
element = browser.find_element(By.CSS_SELECTOR, “h1”)

27
Q

Which is more convenient to use for checking the existence of an element?

A

find_elements