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,220 points
3,608 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,250 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,130 points
5,140 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
1,536 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,130 points
83 views
0 votes
1 answer

Using XPath with Selenium-Java code

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

answered Apr 13, 2018 in Selenium by king_kenny
• 3,610 points
54 views
0 votes
1 answer

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,070 points
435 views
0 votes
1 answer
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,130 points
786 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
430 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,250 points
1,792 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,250 points
200 views