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

421
Vistas
Execute JavaScript code in Selenium using JavaScript

I'm starting with test automation in Selenium. I'm writing tests in JavaScript and I want to execute 'pure' JavaScript code in them, for example

alert('Hello World');

But I'm getting an error: "(node:12988) UnhandledPromiseRejectionWarning: ReferenceError: alert is not defined".

There's many tutorials how to execute JS code in Selenium using Python, Java, C# etc. but is it possible to execute JavaScript code in Selnium using JavaScript?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

alert() function is only available for browser windows. use console.log('Hello World'); instead.

else if you explicitly want to use the alert and make your browser to show the alert popup you can run any javascript code in the current browser instance using JavaScriptExecutor below are sample codes if at all you want to do so.(not recommended as it doesn't add any value)

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("alert('Hello World');");

refer to the below answer too. Node.js Alert Causes Crash

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