2

I need some help on checking if the button is disabled , attaching the screen shot of dom for reference, tried isEnabled() function from WebDriver, but it's returning true.

Need to check if this button is disabled

0

2 Answers 2

2

You can check if the element has disabled attribute. If it exists you will get String results, if not you will get null

WebElement button = driver.findElement(locator);
bool isDisabled = button.getAttribute("disabled") != null;
Sign up to request clarification or add additional context in comments.

Comments

1

There are two way to check if the button is disabled as follows:

  • Using try-catch{}:

    try {
        //css
        driver.findElement(By.cssSelector("fieldset.checkbox button.calvary-button[disabled]"));
        //xpath
        //driver.findElement(By.xpath("//button[@class='calvary-button' and contains(.,'Continue')][@disabled]"));
        System.out.println("Button is disabled");
    } catch (NoSuchElementException e) {
        System.out.println("Button is enabled");
    }
    
  • Using findElements() and and assert zero length response:

    if(driver.findElements(By.cssSelector("fieldset.checkbox button.calvary-button[disabled]")).size()>0)
        System.out.println("Button is disabled");
    else
        System.out.println("Button is enabled");
    

2 Comments

This checks if the button exists, not if it disabled.
Exactly, if the button exists along with the attribute disabled e.g. [disabled]. Sysouts are configurable.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.