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

212
Views
How to Set innerText By ElementHandle with Puppeteer?

I'm trying to set the innerText of an HTML element in a Puppeteer test environment and cannot (easily) get the element by CSS selector, so I'm getting the elementHandle via:

let [ el ] = await page.$x(`//span[contains(text(), 'addTestFile.pdf')]`)

I normally set innerText for testing purposes using evaluate, but I need a selector for that, e.g.:

await page.evaluate(() => document.querySelector('mySelector').innerText = '⚠️DOM modified for testing purposes⚠️')

Can I set innerText of a given elementHandle without a CSS selector?

I see I can get the value with await el.getProperty('innerHTML') but I'm not finding a way to set it.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I figured it out: I can use evaluate on the elementHandle as so:

let [ el ] = await page.$x(`//span[contains(text(), 'addTestFile.pdf')]`)
await el.evaluate(element => element.innerText = '⚠️DOM modified for testing purposes⚠️')
about 4 years ago · Juan Pablo Isaza 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!