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

134
Views
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 answers
Answer question

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 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!