In my app I have two <select> tags. The first one changes the options inside the second one and enables it in the onchange event.
When I use the Select object provided by Selenium2 it doesn’t fire that event when running in IE8 (works great in FF and when I do it manually).
Select select = new Select(getElementByName(name));
element.selectByValue(value);
The first <select> changes as expected. However, the second <select> remains empty and disabled. I tried this as a workaround:
if(ie) {
WebElement select = getElementByName(name);
WebElement option = select.findElement(By.cssSelector("[value='"+value+"']"));
List<WebElement> options = select.findElements(By.cssSelector("option"));
//select the first element
options.get(0).click();
//make sure the select is focused
select.click(); //open
select.click(); //close
Keyboard keyboard = getWebDriver().getKeyboard();
for(int i = 0; i < options.size() && option.getAttribute("selected") == null; i++) {
keyboard.pressKey(Keys.DOWN);
//note: if i do a Thread.sleep(100); here, it works more consistently, but still not 100%
}
} else {
// Do the above snippet
}
but now I get inconsistent results. The desired <option> always gets selected, while only sometimes does the event get fired.
Obviously the best option is getting the Select to work in IE8. Has anyone else seen this issue? Seems like a bug in Selenium2. Is there a known workaround for this?
After talking with some of the Selenium folk in the #selenium IRC chat room I settled on this fix: