[go: up one dir, main page]

0% found this document useful (0 votes)
7 views8 pages

Day - 4 - Dynamic Xpath, CSS

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views8 pages

Day - 4 - Dynamic Xpath, CSS

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Xpath Locator:-

1. Absolute xpath:-
WebSite:- index.html
For Example:- for username text box /html/body/form/div[1]/input[2]
2. Relative xpath:-
 Syntax:- //tagname[@attribute=’value’]
 WebSite:- Mercury Tours
For Example:- for city text box
driver.findElement(By.xpath("//input[@name='city']")).sendKeys(
"Tumsar");
3. Dynamic xpath:-
a. Parent:-
Syntax:- //E1/parent :: E2
 E1- child locator element
 E2- parent locator element
WebSite:- HTML_page
For Example:- for chrome browser
driver.findElement(By.xpath("//option[@value="chrome "]/ parent
::select")).sendKeys("InternetExplore");
b. Child :-
Syntax:- //E1/child :: E2
 E1- parent locator element
 E2- child locator element
WebSite:- index.htm
For Example:- for cancel button //div[2]/child:: button
c. Sibling :-
i. Preceding Sibling:-
Syntax:- //E1/preceding-sibling ::E2
Website:- Demo Web Shop
For Example:- for gender selection
driver.findElement(By.xpath("//label[@for='genderfemale']
/preceding-sibling:: input")).click();
ii. Following Sibling:-
Syntax:- //E1/preceding-sibling ::E2
Website:- index.html
For Example:- for password text box
//input[1]/following-sibling ::input
iii. Immediate Preceding Sibling:-
Syntax:- //E1/preceding-sibling ::*
Website:- index.html
For Example:-
for drop-down button //button/preceding-sibling ::*[1]
iv. Immediate Following Sibling:-
Syntax:- //E1/following-sibling ::*
Website:- index.html

For Example:- for username text box


//label[@for=’uname’]/following-sibling ::*[1]

You might also like