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

256
Visualizações
How to handle waitForSelector when selector is not found

I'm trying to wait for a selector. When the selector is not available, which can happen I would expect to catch that error in the .catch() and be able to proceed with my program. Instead I get the UnhandledPromiseRejectionWarning error.

How can I write a program that can handle selectors that is not found or times out?

Code

await page.waitForSelector('#step3 > div > div > div > div.time-selection-wrapper > div.v-card.v-sheet.theme--light > div > div > div.v-picker__title.primary-color > div > div.v-picker__title__btn.v-date-picker-title_custom1.v-picker__title__btn--active > div', {timeout: 5000})
    .then(async () => {
        console.log("Entered THEN")
    })
    .catch((e) => {
        if (e instanceof puppeteer.errors.TimeoutError) {
            console.log("Timeout")
        }
    })

Output

Timeout (node:9540) UnhandledPromiseRejectionWarning: Error: Node is either not clickable or not an HTMLElement at ElementHandle.clickablePoint (/home/john/git/myproject/node_modules/puppeteer/lib/cjs/puppeteer/common/JSHandle.js:412:19) (node:9540) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:9540) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

about 4 years ago · Juan Pablo Isaza
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