2017-07-07 62 views
0

我想獲取元素的文本。獲取禁用下拉列表元素的文本

這是禁止模式下拉框中:

<select disabled="" readonly="readonly" onchange="onChange('incident.priority');" style="; " id="incident.priority" class="form-control readonly disabled" ng-non-bindable="true" name="incident.priority"> 
    <option value="">-- None --</option> 
    <option value="1">1 - Critical</option> 
    <option value="2">2 - High</option> 
    <option value="3">3 - Moderate</option> 
    <option value="4">4 - Low</option> 
    <option value="5">5 - Planning</option> 
</select> 

我使用:

JavascriptExecutor jse = (JavascriptExecutor)driver; 
WebElement element = driver.findElement(By.xpath("//select[@id='incident.priority']")); 
String s = (String) jse.executeScript("return arguments[0].text" + "", element); 
System.out.println("Priorityvalue= " + s); 

輸出爲null。我想獲取該禁用元素文本。

回答

0

嗯,我不知道如何禁用屬性會影響這個,但當使用下拉框用戶SelectElement類。

IWebElement element = driver.FindElement(By.CssSelector("select[id='incident.priority']")); 
SelectElement elementDdl = new SelectElement(element); 
var text = elementDdl.SelectedOpiton.Text; 

現在,這是C#代碼,但方法和類應該全部命名相似。

+0

其工作感謝你 – ramu

+0

很高興的工作,如果這解決了你的問題,請你接受答案,以便其他人知道它的工作。 –