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

503
Vistas
puppeteer - Error: Evaluation failed: DOMException: Failed to execute 'querySelector'

I'm trying to select some nested divs using puppeteer $$eval. I've copied the XPath of the DOm elements I need to select but seems not working.

    //XPath //*[@id="app"]/main/div/div/div[2]/div/div/div/div[1]/ul/li/a/span
    await page.waitForSelector('//*[@id="app"]/main/div/div/div[2]/div/div/div/div[1]/ul/li/a/span')
    const names = await page.$$eval('//*[@id="app"]/main/div/div/div[2]/div/div/div/div[1]/ul/li/a/span', (el) => {
        return el.map( n => n.innerHTML )
    })
    citiesList.push(names)

    //XPath //*[@id="app"]/main/div/div/div[2]/div/div/div/div[1]/ul/li/a
    await page.waitForSelector('//*[@id="app"]/main/div/div/div[2]/div/div/div/div[1]/ul/li/a')
    const href = await page.$$eval('//*[@id="app"]/main/div/div/div[2]/div/div/div/div[1]/ul/li/a', (el) => {
        return el.map( a => a.getAttribute('href') )
    })
    citiesLinks.push(href)

With this code I will get always this error

Error: Evaluation failed: DOMException: Failed to execute 'querySelector' on 'Document': '//*[@id="app"]/main/div/div/div[2]/div/div/div/div[1]/ul/li/a/span' is not a valid selector

How I can use xpath with $$eval correctly?

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

0

I've solved by targeting directly the DOM elements I need. In my case I have an li tag with .list-item bootstrap class.

 await page.waitForSelector('li.list-item > a', (el) => {
   return el.map( a => a.getAttribute('href') )
 })
 citiesLinks.push(href)
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