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

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

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