I'm trying to get the drop-down options of a selector. When I'm accessing the website with Chrome, and use F12 to look at the HTML, the part I'm dealing with looks like this:
<select name="routeSelector" onkeypress="selectorKeyPress(this, event);
return false;" onfocus="clearKeyBuffer(this)"
onchange="selected(this);routeSelected()">
<option value="701">701</option>
<option value="702">702</option>
<option value="703">703</option>
<option value="104">104</option>
... etc
</select>
However, when I use selenium (java) to access this page, I get
<select name="routeSelector" onkeypress="selectorKeyPress(this, event);return false;" onfocus="clearKeyBuffer(this)" onchange="selected(this);routeSelected()">
<option selected="selected">
_________________________
</option>
</select>
Thus I cannot get the options.
My code looks like this:
public class Foo {
public static void main(String[] args) {
HtmlUnitDriver driver = new HtmlUnitDriver();
try {
driver.get("http://***.html");
} catch (Exception e) {
System.out.println(e.toString());
}
driver.setJavascriptEnabled(true);
Select select = new Select(driver.findElement(By.name("routeSelector")));
List<WebElement> options = select.getOptions(); // return only 1 blank element as above
System.out.print(driver.getPageSource());
driver.quit();
}
I've also tried to perform click on the selector, or refreshing the page, which all doesn't work. I'm guessing there is some Javascript on this webpage involved?
Thanks in advance!
-- Java version 7 Selenium version 2