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.
2 Answers
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
Guy
This checks if the button exists, not if it disabled.
undetected Selenium
Exactly, if the button exists along with the attribute disabled e.g.
[disabled]. Sysouts are configurable.