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

213
Visualizações
Selenium JavaScript Try Catch block is not working as expected

I am trying to throw an error on the console if the first link of bing search results is clicked. My code is working fine until the first link is opened, but I am not seeing any message on the console that first link is successfully clicked and when I make an intentional code change to catch error, catch is not throwing error. I am using node.js, selenium and edge webdriver. Please help me fix this.

const { Builder, By } = require('selenium-webdriver');
async function launchEdgeBing() {
  let driver = await new Builder().forBrowser('MicrosoftEdge').build();

  await driver.get('https://bing.com');
  await driver.manage().window().maximize();

  const element = await driver.findElement(By.id('sb_form_q'));
  await driver.sleep(5000);
  await element.sendKeys('latest news');
  await element.submit();
  await driver.sleep(5000);
  try {
    const clickFirstResult = await driver.findElement(
      
      By.className('b_title')
    );
    clickFirstResult.click();
    await driver.sleep(5000);
   
    var title = await driver.getTitle();
    console.log('Title is:', title);
  } catch (e) {
    if (e == null) {
      console.log('First link opened successfully');
    } else {
      console.log('Error is:', e);
    }
  } finally {
    await driver.quit();
  }
}
launchEdgeBing();
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