preceding-sibling in xpath, Selenium?

0 votes
Jun 1, 2018 in Selenium by walter 123
• 240 points
5,319 views

1 answer to this question.

0 votes

Here, ul has 8 children(8-li) on total.

 And, each li has 7 more siblings(i.e brothers/sisters). Now, suppose you want to identify the 1th li and also 2nd li where only third li can be identified uniquely.

Identifying the 3nd li element, via the xpath

//li[@class='dropdown forum_blog hidden-xs']

NOW,

if we want the identify the 1th li then how do we proceed???

Here we can make use of the preceding-sibling to

 identify the 1st  element by

//li[@class='dropdown forum_blog hidden-xs']/preceding-sibling::li[2]

Where as the 2nd element can be identified as

//li[@class='dropdown forum_blog hidden-xs']/preceding-sibling::li[1]

Note: preceding-sibling::[1]  and preceding-sibling::[2] work in descending order.

answered Jun 1, 2018 by Vinita
• 220 points

Related Questions In Selenium

0 votes
1 answer

XPath for the elements with no ID or Name in Selenium Webdriver

Use like this or similar to this: //div[@id="top-level-menu-item-3"]/div[@class="filter-label"] //div[@id="top-level-menu1"] ...READ MORE

answered Apr 17, 2018 in Selenium by Meci Matt
• 9,460 points
2,803 views
0 votes
1 answer

Using XPath preceding-sibling correctly

Since all buttons are on the same ...READ MORE

answered Apr 18, 2018 in Selenium by Vardy
• 2,360 points
8,460 views
0 votes
1 answer

Which is preferred more in Selenium Absolute or Relative XPath

Absolute XPath is the direct way to ...READ MORE

answered Apr 20, 2018 in Selenium by Meci Matt
• 9,460 points
2,167 views
0 votes
1 answer

How to get next sibling element using XPath and Selenium for Java?

Below code will help you: Try following-sibling axis : WebElement ...READ MORE

answered May 15, 2018 in Selenium by Samarpit
• 5,890 points
12,204 views
0 votes
1 answer

Preferring CSS over XPath in Selenium

Advantages of using CSS: They are faster More readable CSS ...READ MORE

answered May 31, 2018 in Selenium by Meci Matt
• 9,460 points
96 views
0 votes
1 answer

Getting the proper xpath for date picker in selenium

Try to use explicit wait. Sometimes it ...READ MORE

answered Jul 5, 2018 in Selenium by Samarpit
• 5,890 points
2,600 views
0 votes
1 answer

What is the use of Sibling in Xpath?

Using sibling keyword, we can fetch a ...READ MORE

answered Jan 9, 2019 in Selenium by Frankie
• 9,810 points
709 views
0 votes
1 answer

What is Xpath and what are the types of it in Selenium Webdriver?

Hi Piyush, XPath is defined as XML path. It is ...READ MORE

answered May 8, 2019 in Selenium by Pratibha
• 3,690 points
1,098 views
0 votes
2 answers
0 votes
2 answers

What is following-sibling in selenium?

Xpath=//*[@type='text']//following::input[2] READ MORE

answered Sep 4 in Selenium by Sri
• 2,970 points
7,074 views