Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

191
Views
How do I target a button with extra wrapper tag in XPath?

I tried targeting the below, but can't seem to get it to work. The error I get is

Error: Node is either not clickable or not an HTMLElement.

JavaScript

const btn = await page.$x(//button[contains(., 'My Button')])
await btn[0].click()

HTML/XML

<div>
<button>
<translate original="My Button">My Button</translate>
</button>
</div> 
about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

If you truly want substring matching (for example, all of "My Button", "Not My Button", and "My Buttonless Shirt"), then use contains() as @Prophet shows.

On the other hand, if you simply want to abstract away whitespace (along with any elements wrapping the targeted text), then use normalize-space():

//button[normalize-space() = 'My Button']

This selects the button element whose space-normalized string value is exactly 'My Button'.

See also

  • How to use XPath contains() for specific text?
  • What does contains() do in XPath?
about 4 years ago · Santiago Gelvez Report

0

Instead of

//button[contains(., 'My Button')]

Try

//translate[contains(., 'My Button')]

Or maybe

//*[local-name()='translate' and contains(., 'My Button')]
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!