Reputation: 11071
There is a simplified html table
<table>
.....
<tr/>
<tr class="base"/>
<tr class="check"/>
<tr/>
<tr class="base2"/>
<tr class="check"/>
.....
</table>
With selenium I have an element with class "base" found early.
var row = table.FindElement(By.ClassName("base"));
I need to get next row with class 'check' but only in case that it is present (otherwise an exception).
var nextRow = row.FindElement(By.XPath("following-sibling::tr[@class='check'][1]")
The problem is that this xpath gives me row with class 'check' after row with class 'base2' in case row after my class is absent.
Is it possible by 'following-sibling' to verify onle next element but not all of them?
Upvotes: 0
Views: 1799
Reputation: 9058
Try this with CSS locator - tr[class='base'] + tr[class='check']
Will return next row if class 'check' else nothing.
If you want the Xpath :
//tr[@class='base']/following-sibling::tr[1][@class='check']
Upvotes: 5