Locator types Flashcards

1
Q

Use XPath to find div with id “content” which contains table, navigate to input in the 3rd td of the second tr, and enter number 100 into input.

A

driver.findElement(
By.xpath(“.//*[@id = ‘content’]/table/tr[2]/td[3]/input”))
.sendkeys(“100”);

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

How to find an HTML tag using XPath? Show example.

A

with //
Example: driver.findElement(By.xpath(“//form”)

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

Using XPath to find a form with action “blah”

A
driver.findElement(
By.xpath("//form[@action='blah']");
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What “.” means in XPath?

A

. represents the current element.
For example:
.//input[@name=’radio’] and //input[@name=’radio’]
The first statement looks for all “inputs” with name=’radio’ beneath the actual element.
The second statement looks globally for all input elements with the name ‘radio’.

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

How to specify any element using XPath?

A

With

*
for example:
driver.findElement(By.xpath(".//*[@id = 'content']");
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are / and . in XPath?

A

They represent absolute and relative XPaths (/ vs .)
/ introduces an absolute location path, starting at the root of the document.
. introduces a relative location path, starting at the context node.

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

How to search by 2 attributes using XPath?

A

driver.findElement(By.xpath(“//input[@name=’name’][@value=’some-value’]”);

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

What “*” means in XPath?

A

Any tag, for example: driver.findElements(By.xpath(“.//*[@name = ‘radio-buton’]”));

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

How to use OR and AND operators in XPath?

A

//input[@id=’name’ or @name=’name’]

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

Using XPath, how to find “a” link with text “Click Me”

A

//a[text()=’Click Me’]

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

Using XPath, how to find any element with text “Click Me”

A

//*[text()=’Click Me’]

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

Using XPath, how to find element containing partial text

A
//tagname[contains (@Attribute, ‘Value’)]

or using Text:
//tagname[contains(text(),'XYZ')]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How to find elements by multiple class names?

A

By.cssSelector(“.class1.class2”)
or
By.cssSelector(“div.class1.class2”)
or
By.xpath(“//div[contains(@class, ‘class1’) and contains(@class, ‘class2’)]”

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

How to maximize window using WebDriver?

A

driver.manage().window().maximize();

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