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

130
Views
How to get the selector after filtering from selectorAll?

I want to get selector from nodelist for specific filtering to pass to puppeteer waitForSelector that need css selector. i expect cause apple is 2nd child. i expect get button:nth-child(2)

const fruits = document.querySelectorAll('button');

for (const fruit of fruits) {
  if (fruit.textContent == 'Apple') {
    // get the element handle and pass to waitForSelector
    console.log('Apple')
  }
}
<button type="button">Orange</button>
<button type="button">Apple</button>

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

0

As suggest from andy, i solved it this ways. credit to andy

const fruits = document.querySelectorAll('button');

for (const fruit of fruits) {
  if (fruit.textContent == 'Apple') {
    fruit.setAttribute('data-type', 'Apple');
    break
  }
}

return document.querySelector('button[data-type=Apple]')
<button type="button">Orange</button>
<button type="button">Apple</button>

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!