Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

210
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda