Reputation: 35
In the example below I'm trying to click on Follow Me where the adjacent(ish) <div>
is equal to David. This is one of many <div class='_1m'
on the page all with the same structure.(does that make sense?)
Sorry first time posting a problem and a forgot one major detail. I know that I'm looking for David but I don't know what the 'Follow Me' Value will be. It changes on each record.
<div class="_1m">
<div class="_8h"><img src="/2323.GIF" /></div>
<div class="_1j">
<div class="_1c">David<span class="_13">abc</span></div>
<div>
<span class="_1v">ABCD</span>
<span class="_1v">1234</span>
</div>
<div>7890</div>
</div>
<div class="_3h">
<div class="_n0">
<span class="_bn"><span class="_la">Follow Me</span></span>
</div>
</div>
</div>
Upvotes: 1
Views: 315
Reputation: 193088
To click on Follow Me where the adjacent <div>
contains the text David you can use the following Locator Strategy:
Using xpath and following:
//div[contains(., 'David')]//following::span[3]/span
Using xpath, following and the text Follow Me:
//div[contains(., 'David')]//following::span[3]/span[text()='Follow Me']
Upvotes: 2
Reputation: 7708
Use below xpath //div[@class='_1c'][contains(.,'David')]/../following-sibling::div//span[@class='_la'][contains(.,'Follow Me')]
Explaination:
//div[@class='_1c'][contains(.,'David')]
loate the David/..
move to one parent node of David because follow me emement is sibling of that parent div/following-sibling::div
locate immediate following sibling div//span[@class='_la'][contains(.,'Follow Me')]
Loate the span which has Follow me textUpvotes: 1