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

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