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

185
Visualizações
Js Node Selenium Try-Catch Js Error not working

I'm trying to simulate clicking on an element that is rendered after a certain iteration of document.readyState='complete'. To get around the readyState issue, I thought of try-catching the executeScript command to just make it retry until it works.

But for some reason Node / Selenium just stops working entirely from the resulting Js error:

Cannot read properties of undefined (reading 'parentElement')

Any ideas on how I should solve this? Here's part of my code. It'll open up the supplied url (item) and should execute the command as soon as the element icon-download is rendered.

async function getFileFromUrl(item) {
  var command = "document.getElementsByClassName('icon-download')[0].parentElement.click()";
  driver.get(item);
  do {
    await delay(500);
    try{
      driver.executeScript(command);
    } catch (e) {
      continue;
    }
    break;
  } while (true);
  await delay(3000);
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Ok so I managed to fix it by prefixing the driver-commands with Await. If they return an exception it's recognized by Node now. Code below:

async function getFileFromUrl(item) {
  var command = "document.getElementsByClassName('icon-fpk icon-download-xls')[0].parentElement.click()";
  await driver.get(item);
  do {
    await delay(500);
    try{
      await driver.executeScript(command);
    } catch {
      continue;
    }
    break;
  } while (true);
  await delay(3500);
}
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