有没有办法从禁用的ddl中获取显示的值?试过以下代码:
Select select = new Select(Locator);
WebElement option = select.getFirstSelectedOption();
String text= option.getText();
显示错误:元素应该已被选中但是已输入。该元素实际上是选择但禁用。
法院:
<select class="form-control dirty-checked-field" disabled="disabled" id="Pyear" name="Sections[0].PortfolioYear" title="2019">
public void getList_ByID(String id_element, int list_index_to_click) {
try {
WebElement web_el = driver.findElement(By.id(id_element));
Select select = new Select(web_el);
List<WebElement> option = select.getOptions();
option.get(list_index_to_click).getText();
} catch (Exception e) {
//errors
}
}
哪里:
id_element is *Pyear*
list_index_to_click is the index of the drop-down list,
e.g. if your drop-down list has only 1 element then index is 0
其他:
谢谢,