Reputation: 5226
So let's say my structure looks like this at some point:
..........
<td>
[...]
<input value="abcabc">
[...]
</td>
[...]
<td></td>
[...]
<td>
<input id="booboobooboo01">
<div></div> <=======I want to click this!
</td>
.........
I need to click that div, but I need to be sure it's on the same line as the td containing the input with value="abcabc"
. I also know that the div I need to click (which doesn't have id or any other relevant attribute I can use) is in a td at the same level as the first td, right after the input with id CONTAINING "boo" (dynamically generated, I only know the root part of the id). td's contain nothing relevant I can use.
This is what I tried as far as xpath goes:
//input[@value='abcabc']/../td/input[contains(@id,'boo')]/following-sibling::div
//input[@value='abcabc']/..//td/input[contains(@id,'boo')]/following-sibling::div
None of them worked, of course (element cannot be found). I want to know if there's a way of selecting that div and how.
EDIT: //input[@value='abcabc']/../../td/input[contains(@id,'boo')]/following-sibling::div
is the correct way. This was suggested by the person with the accepted answer. Also note that he offered a slightly different way of doing it. See his answer for details.
Upvotes: 0
Views: 3177
Reputation: 25076
Another XPath that may work, is a bit more simple:
//input[@id='booboobooboo01']/../div[1]
Upvotes: 1
Reputation: 338386
Try
//input[@value='abcabc']/ancestor::tr[1]/td/input[contains(@id,'boo')]/following-sibling::div[1]
Note that //input[@value='abcabc']/..
only goes up to the parent <td>
, that's why your's did not work.
Upvotes: 3