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

85
Views
Puppetteer Selects using Xpath

I am trying to select an option dynamically using puppeteer but I'm running into some problems on how to get it correctly. I need to get the actual value associated with the option tag. This is making my problem a bit harder. I searched a little bit and found that some people are using Xpath to make the problem a little easier to get, but it seems that my Xpath is not working correctly, as I'm getting an error ->

The string '//select[@id = "wrestler"]/option[text() = Henri Mugnier]' is not a valid XPath expression.

Henri Mugnier is at index 0 in my holderArr array.

Here is my small code snippet.

const option = (await frame.$x(
    `//select[@id = "wrestler"]/option[text() = ${holderArr[i].name}]`
))[0];

holderArr is getting passed in from another function, it's an array of objects. The dropdown is a list of names, but the value for each of them is just random numbers, So I'm hoping that using an xpath and then grabbing the value with a function like this

const value = await (await option.getProperty('value')).jsonValue();

Steps to reproduce:

  1. Go to https://www.trackwrestling.com/seasons/
  2. 2021-22 High School Boys > select 'Tennessee Secondary School Athletic Association'
  3. Click 'Team' at the top
  4. Select any team
  5. Select 'Matches' or More
  6. Select Matches (This dropdown is the one I'm trying to access)
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This is how I ended up getting it to work. This will give you the value property on the option tag using puppeteer.

 let [optElementHandle] = await frame.$x(`//select[@id="wrestler"]//option[contains(text() , "${holderArr[i].name}")]`)
    const text = await optElementHandle.getProperty('value')
    const value = await text.jsonValue()
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!