preceding-sibling in xpath Selenium

0 votes
Jun 1, 2018 in Selenium by walter 123
• 240 points
13,757 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
6,847 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
13,251 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
4,117 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,910 points
20,280 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
396 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,910 points
4,096 views
0 votes
1 answer

What is the use of Sibling in Xpath?

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

answered Jan 10, 2019 in Selenium by Frankie
• 9,830 points
1,612 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 9, 2019 in Selenium by Pratibha
• 3,690 points
5,064 views
0 votes
2 answers

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

some of the controls not have id ...READ MORE

answered Sep 4, 2020 in Selenium by Sri
• 3,190 points
1,563 views
0 votes
2 answers

What is following-sibling in selenium?

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

answered Sep 4, 2020 in Selenium by Sri
• 3,190 points
11,289 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP