2

I'm trying to find an element, but it doesn't have any ID nor anything else. HTML looks basically like this:

<div class="item_select">
   <span class="item_selection_number">A
</span>
</div>

<div class="item_select">
   <span class="item_selection_number">B
</span>
</div>

I'm trying to find the B element on every page, but its position varies every time, so I can't use span[1] or n-th child(1). How can I do this?

4
  • We need a larger context to figure out robust way. Please post more of your HTML. That said, you could try matching text. Commented Jul 8, 2019 at 18:21
  • Iterate over all the span tags and check the text. Commented Jul 8, 2019 at 18:22
  • Get all of the item_selection_number then check the innerText Commented Jul 8, 2019 at 18:22
  • Welcome to SO. Your question is too broad. Please take the time to read How to Ask and the other links found on that page. Commented Jul 8, 2019 at 18:23

1 Answer 1

3

Use this xpath selector, its the best way when selecting text

//span[@class='item_selection_number'][contains(text(),'B')]
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! That helped.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.