简体   繁体   中英

Check if element is disable using selenium

So i have this WebElement (now in disable mode):

<select id="id1" name="name" disabled=""><option value="">Select...</option>
<option value="false">No</option>
<option value="true">Yes</option></select>

Not disable:

<select id="id1" name="name" ><option value="">Select...</option>
<option value="false">No</option>
<option value="true">Yes</option></select>

So my question is how to check if this element is disable or not?

您可以使用isEnabled()来验证它是否已启用。它返回布尔值。如果返回true,则元素被启用;如果返回false,则元素被禁用。

You should use isDisplayed method of WebElement.

WebElement el = driver.findElement(By.id("id1"));
el.isDisplayed ()

if you want to check how many lists of elements are disabled or enabled, you can use the below syntax.

List btn = driver.findElements(By.tagName("button"));

    int countEnable = 0;
    int countDisable = 0;
    for (int i = 0; i < btn.size(); i++) {
        if (btn.get(i).isEnabled()) {
            countEnable++;
        } else
            countDisable++;
    }
    System.out.println("Total Enabled button available in web page is : " + countEnable);
    System.out.println("Total Disbaled button available in web page is " + countDisable);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM