Sometimes you may encounter a scenario where selenium Select class can not be used to select the value from the drop down or list box in any browser like internet explorer, google chrome or firefox.
Sometime situation is more difficult because after selecting the value from drop down, other controls on the page get auto populated.
So basically there are 2 problems.
Above script will select value X from the drop down.
After this you will have to trigger the on change event on the drop down using below code.
This will fire the drop down change event on the web list.
What do you think on above selenium topic. Please provide your inputs and comments. You can write to me at reply2sagar@gmail.com
Sometime situation is more difficult because after selecting the value from drop down, other controls on the page get auto populated.
So basically there are 2 problems.
- Selenium unable to select the value from the drop down.
- Java script event does not get invoked. So other controls do not get auto populated.
WebElement c = driver.findElement(By.xpath("//select[@name='empType']"));
((JavascriptExecutor) driver).executeScript("arguments[0].value='X';",c);
Above script will select value X from the drop down.
After this you will have to trigger the on change event on the drop down using below code.
((JavascriptExecutor) driver).executeScript( "var evt = document.createEvent('HTMLEvents'); evt.initEvent ('change', true, true); arguments[0].dispatchEvent(evt);",c);
This will fire the drop down change event on the web list.
What do you think on above selenium topic. Please provide your inputs and comments. You can write to me at reply2sagar@gmail.com
No comments:
Post a Comment