preceding-sibling in xpath, Selenium?

0 votes
Jun 1, 2018 in Selenium by walter 123
• 240 points
1,701 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,420 points
1,260 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,250 points
3,988 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,420 points
1,064 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,130 points
5,544 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,420 points
42 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,130 points
1,445 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 in Selenium by Frankie
• 9,810 points
178 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 in Selenium by Pratibha
• 2,780 points
139 views
0 votes
1 answer

what is the need of xpath when you have attributes like id ,class,name in selenium?

It is not necessary that every element ...READ MORE

answered Jun 1, 2018 in Selenium by Vinita
• 220 points
167 views
0 votes
1 answer

What is following-sibling in selenium?

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

answered Jun 1, 2018 in Selenium by Vinita
• 220 points
2,220 views