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

115
Views
RobotFramework - Execute Javascript

I'm trying to inject my browser with JavaScript Executor function to get back into running instance of a browser. For it, I'm using the keyword "Exectute JavaScript" My code looks like this:

SeleniumLibrary.Execute Javascript           JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("alert('OK')")

Error looks like this:

JavascriptException: Message: javascript error: Unexpected identifier

(Session info: chrome=92.0.4515.107)

It looks like import for JavaScriptExecutor? How can this be done?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Can you try below code

SeleniumLibrary.Execute Javascript   alert('OK')
about 4 years ago · Juan Pablo Isaza Report

0

The alert should be handled with the Handle Alert keyword as you seem to have done already. For returning to earlier browser instance Selenium provides two entities which can be used. You may want to see the Browsers and Windows section of the SeleniumLibrary documentation.

Basic use case is that when opening browser, you'll give it an alias and then use Switch Browser to get back to that browser instance. Within that browser you may have multiple pages open, they can be accessed with normal locators by using Switch Window keyword. For example I would commonly use the window URL as that tends to have at least some unique part in it. If none of the URL, title, or name are unique, by using keyword Get Window Handles returns a list of windows within that browser. In your case, expecting no other windows are opened during the test, the main browser window can be found with argument MAIN.

You may consider this incomplete example and fill in your specifics which you did not provide in the question.

Test 1
    Open Browser    ${your URL}    alias=browser1
    # Do whatever triggers the alert
    Handle Alert
    Switch Window    MAIN
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!