0

I would like to match a <button> element with a certain text, which is sometimes closed in another element within the button, eg.:

<div @class="buttonset"> 
  <button>Close</button>
</div>

<div @class="buttonset"> 
  <button>
    <span>Close</span>
  </button>
</div>

The xpath query //div[@class='modal-buttonset']/button[text()='Cancel'] gives me only result from the highest level.

How to match the text on all levels?

1
  • 1
    Attributes in XML and HTML do not begin with @ -- your example confuses markup syntax with XPath syntax. Hopefully that's a question typo, not your actual data. Commented Mar 7, 2019 at 16:06

2 Answers 2

1

Try the following:

//div/button[descendant::text()="Close"]
Sign up to request clarification or add additional context in comments.

Comments

1

This XPath,

//button[normalize-space() = 'Close']

will select all button elements whose space-normalized string value is 'Close', regardless of any additional wrapper elements, as requested.

Comments

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.