1

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>
J IOI
  • 15
  • 4

2 Answers2

2

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']
    
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
1

Use below xpath //div[@class='_1c'][contains(.,'David')]/../following-sibling::div//span[@class='_la'][contains(.,'Follow Me')]

Explaination:

  1. //div[@class='_1c'][contains(.,'David')] loate the David
  2. /.. move to one parent node of David because follow me emement is sibling of that parent div
  3. /following-sibling::div locate immediate following sibling div
  4. //span[@class='_la'][contains(.,'Follow Me')] Loate the span which has Follow me text
NarendraR
  • 6,770
  • 7
  • 35
  • 69