Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

124
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda