【发布时间】:2019-07-09 08:31:46
【问题描述】:
我正在尝试从下拉列表的多个选项中选择一个选项,但由于它显示索引值为 1,因此无法选择
【问题讨论】:
标签: java html selenium-webdriver
我正在尝试从下拉列表的多个选项中选择一个选项,但由于它显示索引值为 1,因此无法选择
【问题讨论】:
标签: java html selenium-webdriver
你得到的不是真正的细节,但如果你有:
<select id="myselect">
<option value="1">1</option>
<option value="2">2</option>
</select>
要选择第二个选项,您可以这样做:
driver.findElement(By.id("myselect")).click();
//you can add a check of visibility of options (WebDriverWait.until(ExpectedConditions.visibilityOfLocatedElement(By.xpath("//select[@id='myselect']/option"))
driver.findElement(By.xpath("//select[@id='myselect']/option[@value='2']")).click();
driver.findElement(By.id("myselect")).click(); //to close the dropdown
【讨论】: