As display is set to 'none' for 'Select' tag, Selenium is unable to identify dropdown list values.
One way of handling is by clicking that dropdown and enabling the list.
Other way is by executing JavaScript to enable the dropdown list and then selecting value using WebDriver's 'Select' API.
Here is the code to handle using JavaScript:
Assuming HTML code for select is as below:
One way of handling is by clicking that dropdown and enabling the list.
Other way is by executing JavaScript to enable the dropdown list and then selecting value using WebDriver's 'Select' API.
Here is the code to handle using JavaScript:
JavascriptExecutor js = (JavascriptExecutor)driver; js.executeScript("document.getElementById('country').style.display='block';"); //Then Select required value Select dropdown = new Select(driver.findElement(By.id("country"))); dropdown.selectByVisibleText("India");
Assuming HTML code for select is as below:
Thanks for this
ReplyDeleteVery Helpful
ReplyDeleteIts a query?
ReplyDeleteWhat is heightened privileges browsers?
http://www.bestqtptraining.com/
very helpful it works!!!!!!!!!!!!!!!!!!
ReplyDeletevery helpful it works!!!!!!!!!!!!!!!!!!
ReplyDeleteThis is a life saver ...
ReplyDeleteI am getting as Javascript Error in my selenium script if i use above code.
ReplyDelete