2017-10-12 55 views
0

我在下拉列表中可以更改的百分比值,一些值被禁用,一些被啓用? 我需要驗證值並檢查它是啓用還是禁用?如何使用WebDriver驗證啓用禁用DropDown的值?

是否有任何方法獲得一個值的XPath並檢查其啓用或禁用?

查找圖像,以獲得更多的細節

enter image description here

+1

檢查firepath一次是否此xpath // select [@ id = level_points]選擇所有選項。如果是的話,然後嘗試根據您的要求選擇選項,如//選擇[@ id = level_points] //選項[@ value ='100'],然後檢查它是否已啓用或禁用,如driver.findElement(By。 xpath(「xpath here」))。isEnabled()如果xpath // select [@ id = level_points]不起作用,那麼驗證一次select選項是否在iframe內。如果是,請切換到iframe,然後按照上述說明操作。 –

+0

謝謝你這幫我抓到元素 – dilRox

回答

1

你可以使用下面的代碼檢查選項是否已啓用或禁用。嘗試使用下面的代碼。

WebElement selectDropDown=driver.findElement(By.xpath(".//select[@id='level_points']")); 
List<WebElement> options=selectDropDown.findElements(By.tagName("option")); 
for(int i=0;i<options.size();i++) 
{ 
try{ 
    String isDisabled=options.get(i).getAttribute("disabled"); 
    //Write the required code if disabled 
    } 
catch(Exception ex) 
    { 
    //Write required code if not disabled 
    } 
} 

我沒有在這臺機器上的Eclipse,所以請採取語法錯誤,如果有的話。 您將在try塊中獲得所有禁用的選項,因爲您擁有該屬性,並且在catch塊中,您將獲得未禁用的選項。

+0

偉大的這幫助我解決我的問題:)謝謝... – dilRox