2

I have this html:

<div tabindex="0" class="ember-basic-dropdown-trigger ember-power-select-trigger ember-power-select-trigger-2568211667 category-select t-ticket-category-select-trigger">
   Building
</div>

<div tabindex="0" class="ember-basic-dropdown-trigger ember-power-select-trigger ember-power-select-trigger-6101225577 category-select t-ticket-category-select-trigger">
  Warehouse
</div>

I would like to access the text in the 2nd div that has the same CSS class name, but am not sure how to access it.

I have some XPath code like this, but this doesn't work:

//*[contains(@class, 't-ticket-category-select-trigger')]
1
  • What environment are you working in? In you're working in Python, you might want to check out the cssselect library, which converts CSS selectors to Xpath (github.com/SimonSapin/cssselect). Commented Jan 13, 2016 at 23:13

1 Answer 1

3

Just access it by index (indexing starts with 1 in XPath):

(//*[contains(@class, 't-ticket-category-select-trigger')])[2]

Or, if it is the last one:

(//*[contains(@class, 't-ticket-category-select-trigger')])[last()]
Sign up to request clarification or add additional context in comments.

2 Comments

Alecxe, I added all CSS classes for these divs to my question. I tried your answer, but can't get it to work. Is the syntax different if there are other CSS classes in the DOM element? Thank you for your help!
@AronYsidoro okay, thanks, quick check - would this work: (//*[contains(@class, 't-ticket-category-select-trigger')])[2] (note the parenthesis)?

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.