簡體   English   中英

Selenium Webdriver Java:如何從禁用的下拉列表中獲取顯示的值

[英]Selenium Webdriver Java: How to get the displayed value from a disabled dropdown list

有沒有辦法從禁用的ddl獲取顯示的值? 嘗試了以下代碼:

Select select = new Select(Locator);
WebElement option = select.getFirstSelectedOption();
String text= option.getText();

顯示的錯誤:應該已經選擇了元素,但是已經輸入了元素。 該元素實際上是“選擇”但已禁用。

DOM:

<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來獲取值

謝謝,

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM