我使用的是Chrome驱动程序和Windows 10操作系统。通过使用select类,我可以从select标签中找到选项。但无法通过索引或visibleText或任何选择选项。
<select class="pull-left" name="status">
<option value="">Status</option>
<option class="select-value" value="Valid" >Valid</option>
<option class="select-value" value="Ivalid">Invali</option>
</select>
Selenium Code-
@FindBy(xpath="//select[@name='status']")
WebElement drop;
Select sel=new Select(drop);
List<WebElement> ls=sel.getOptions();
for (WebElement webElement : ls) {
System.out.println(webElement.getText());
}
sel.selectByVisibleText("Status");
控制台输出: -
org.openqa.selenium.WebDriverException: unknown error: a.tagName.toUpperCase is not a function
(Session info: chrome=56.0.2924.87)
(Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT 10.0.14393 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 55 milliseconds
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:49:13 -0700'