1

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

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
user2405952
  • 41
  • 2
  • 7

2 Answers2

1

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;
Guy
  • 46,488
  • 10
  • 44
  • 88
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");
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352