0

I am trying to write the XPath for the below element but unable to do. I want to write for the Individual. I wrote like this //h3[contains(text(),'Individual')]

<h3 class="dashboradh">
          <strong>My Dashboard</strong>
          <span>Anjana</span> |  Individual        </h3>
1
  • Your h3 does not contain the text in question. You could go for //h3/strong[contains(text(), 'Individual')]/.. to get your Element but the css selector h3.dashboradh should be faster and more resistant against changes.
    – Daniel
    Oct 23, 2018 at 11:46

2 Answers 2

1

There are some white spaces in your string. So use normalize-space() to trim the white spaces as below :

//h3[normalize-space(text()='Individual')]

OR

You should try dot . instead of text() in contains method to match the required text in any node within the tag.

//h3[contains(., 'Individual')]
0

You should use dot . like in previous comment. Dot will look for text in all child nodes. You can also be more specific: //h3//span[contains(text(),'Individual')] or //h3//*[contains(text(),'Individual')] if you don't know type of child element.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.