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

342
Views
Cannot Select Option from Dropdown Menu in Selenium WebDriver using Javascript

I'm trying to select option from a dropdown menu by visible text using Javascript Executor:

JavascriptExecutor executor = (JavascriptExecutor)driver;
        
executor.executeScript("var select = arguments[0]; for(var i = 0; i < select.options.length; i++){ if(select.options[i].text == arguments[1]){ select.options[i].selected = true; } }", element, visibleText);

Although the code above does not throw an exception, the desired option is not selected (the default option remains selected). I am unable to select option using the native Selenium WebDriver Select class because there's a permanent overlay over the element. I tried hiding the permanent overlay with JS as suggested in this response but since the targeted element is a descendant of the overlay element if I hide the overlay element it automatically hides the targeted element too.

Why isn't the JS code selecting the desired option? Is there any other way to select option from drop down via JS/Javascript Executor that might work?

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