Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
920 views
in Technique[技术] by (71.8m points)

selenium - How to use XPath preceding-sibling correctly

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']
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You don't need to go level up and use .. since all buttons are on the same level:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...