Help with XPath neighbor

Please could someone help me get the correct syntax for the xpath here? How can I specify that I want to click on the div with the text “Default”, that neighbors the div with the text “XXX”? I’ve tried dozens of different things and none of them do what I want…

<div class="ui-member-address-card__details">
  <div class="ui-member-address-card__details__head">
    <div class="ui-member-address-card__details__head__title">Work</div>
    <div class="ui-member-address-card__details__head__default ui-member-address-card__details__head__default--highlight">Default</div>
  </div>
  <div class="ui-member-address-card__details__body">XXX</div>
</div>

Thanks!
Graham

//div[text()='Default' and ./ancestor::div/following-sibling::div[text()='XXX']]

1 Like

How about using the following xpaths for your object:
//div[text()='XXX']/preceding-sibling::div[1]/div[2]
or
//div[text()='XXX']/preceding-sibling::div/div[text()='Default']

1 Like

@gengland Did this help? If so, please mark a solution so that we can close this topic. Thank you!

My apologies, I was off work (just became a grandad!). I just tried all three suggestions listed here and they all work, thank you so much to you and grylion54

I just wish i understood how these kinds of xpaths work, for some reason I can’t seem to get my head around them yet. I need a dummies guide to XPaths YouTube video I think! I just found a few, so I’ll make that my afternoon task!

No worries, and huge congrats!!!

Writing xpaths is an art in it’s own right, so don’t feel bad about stumbling through it. It took me a good 2 years before I was really confident with it. Feel free to reach out with further inquiries :slight_smile:

1 Like