Selenium Webdriver Java:如何从禁用的下拉列表中获取显示的值

茶匙

有没有办法从禁用的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

其他:

  1. 尝试使用xpath获取值
  2. 尝试使用attribute = disable来获取值

谢谢,

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章