Using XPath preceding-sibling correctly

0 votes

Below is the code I wrote using Selenium IDE. Problem is with the clicking on a button using preceding-sibling

<td>

<div class="btn-group">

<button class="btn btn btn-danger block" title="Warning, Delete" name="delete" type="button">

<button class="btn btn btn-default block" title="View History" name="history" type="button">

<button class="btn btn btn-default block" title="View Settings" name="settings" type="button">

<button class="btn btn btn-default block" name="device" type="button">

<span class="glyphicon glyphicon-pencil"/>

 Arcade Reader

</button>

</div>

</td>

My path

xpath=//button[contains(.,'Arcade Reader')]/../preceding-sibling::button[@name='settings']

Apr 18, 2018 in Selenium by Martin
• 4,320 points
13,819 views

1 answer to this question.

0 votes

Since all buttons are on the same level you don't need to go level up and use

Use below code:

//button[contains(.,'Arcade Reader')]/preceding-sibling::button[@name='settings']

answered Apr 18, 2018 by Vardy
• 2,360 points

Related Questions In Selenium

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,847 views
0 votes
1 answer

preceding-sibling in xpath, Selenium?

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

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

Returning null element when using following and preceding XPath selector

To identify the <input> tag with respect to the <label> tag ...READ MORE

answered Jun 8, 2018 in Selenium by Samarpit
• 5,910 points
3,231 views
0 votes
1 answer

Using XPath with Selenium-Java code

There is a minor syntax error in ...READ MORE

answered Apr 14, 2018 in Selenium by king_kenny
• 3,710 points
1,011 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
13,747 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,178 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
7,253 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,890 views
0 votes
1 answer

Select an item from a dropdown list using Selenium WebDriver

Use this then it will work - new ...READ MORE

answered Apr 9, 2018 in Selenium by Vardy
• 2,360 points
7,785 views
0 votes
1 answer

JavaScript Executor using Selenium WebDriver

Its working fine but the problem in ...READ MORE

answered Apr 9, 2018 in Selenium by Vardy
• 2,360 points
1,496 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