Reputation: 157
There is a web element:
<select id="sel" onchange="refresh('sel')">
<option value="1"> A</option>
<option value="2"> B</option>
</select>
Because it has onchange
, I can not select the option. My code is like this:
new Select(driver.findElement(By.id("sel"))).selectByValue("1");
But it can not work. Is it possible to make it to work?
Upvotes: 1
Views: 646
Reputation: 544
This is what I'll try to do:(C#)
IWebElement element = driver.FindElement(By.XPath(XPATH_FOR_OPTION));
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].fireEvent('onclick');", element);
Upvotes: 0
Reputation: 521
Use the xpath instead of using id. Because as per the code, it will refresh the screen once u select the value. Try using xpath and after the xpath give some wait period for refreshing.
Upvotes: 1