3

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 ?

3 Answers 3

5

u can use isEnabled() to verify whether it is enabled or disable.it returns boolean .if it returns true the element is enabled if it returns false the element is disabled.

Sign up to request clarification or add additional context in comments.

1 Comment

This should be the accepted answer. @kumar you could add a link to the official docs (e.g. for Python it's: selenium-python.readthedocs.io/…)
0

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);

Comments

-1

You should use isDisplayed method of WebElement.

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

1 Comment

But an element could be displayed AND disabled.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.