Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

416
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!