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

125
Vistas
How would I get an element value by name using Puppeteer?

I want to get the value of this

<input type="hidden" value="12345" name="InitiationTT">

But since it does not have an ID, I would like to retrieve the value by name. I first tried this:

const cii = await page.$("InitiationTT");
const init = await page.evaluate(el => el.getAttribute("value"), cii);

which did not work and threw TypeError: Cannot read properties of null (reading 'getAttribute'), so then I tried this:

const cii = page.evaluate(() => {document.querySelector("input[name=InitiationTT]").value});

which gave me Promise { <pending> } and so I finally tried this:

const cii = document.querySelector("input[name=InitiationTT]").value;

Which gave me ReferenceError: document is not defined so I am assuming that is because I am using NodeJS(?)

These 3 methods did not work and I do not know if Puppeteer has a way of getting a value of an element by it's name. Any help would be appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Make sure your selector is correct. Furthermore, the value property should be available on the <input> element.

const r = await page.$eval('input[name="InitiationTT"]', ({ value }) => value); // 12345

Reference: How to get element value in puppeteer


Note: A similar question has been asked before:

Get the Value of HTML Attributes Using Puppeteer

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