Back

Explore Courses Blog Tutorials Interview Questions
+11 votes
1 view
in DevOps and Agile by (19.7k points)
edited by

I am writing tests for my site using Selenium IDE and I am having trouble with having selenium click 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']

2 Answers

+10 votes
by (62.9k points)

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

the below code:

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

+9 votes
by (106k points)

What is a Sibling:-

The sibling is a keyword which can be used to fetch a web element on which it is related to some other element.

An example that illustrates the use of sibling keyword is as follows, on the basis of sibling element of 'a' we are finding 'h4'

"//div[@class='canvas- graph']//a[@href='/accounting.html'][i[@class='icon-usd']]/following-sibling::h4"

Comming to your error part, since all buttons are on the same level so can use the following:

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

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...