Back to All Scenarios
Scenario 65 of 100
Element Interaction
Beginner
Verifying if an Element is Disabled
π«Scenario Overview
Verifying if an Element is Disabled
Key Takeaways & Cheat Sheet
- βUse element.isEnabled() to query functional element states
- βCheck for presence of disabled attribute tags inside components
- βInspect class list values for styling states (like "disabled" or "readonly")
- βAssert returned boolean values using standard assertion frameworks
Short Direct Answer
To check if an element is disabled, use `element.isEnabled()`, which returns false if the element has a `disabled` attribute. For modern custom elements (like styled divs), verify if the element's `class` or `disabled` attributes contain "disabled" or "aria-disabled" values.
β οΈ Senior Warning (Red Flag)
Do not rely only on isEnabled() for custom modern components. Frontend frameworks (like React or Angular) often make divs look disabled using CSS styles while leaving isEnabled() returning true.
π‘ STAR Deep Dive Explanation & Pro Tip
Custom buttons built from divs do not support standard HTML state properties. You must verify their state by inspecting class attributes or accessibility attributes.
SeleniumAutomation.java
Selenium 4 + JavaWebElement saveBtn = driver.findElement(By.id("save-btn"));
// β
Standard check: returns false if "disabled" attribute is present
boolean standardCheck = saveBtn.isEnabled();
// β
Modern check: inspect class properties for disabled state classes
String classes = saveBtn.getAttribute("class");
boolean classStyleCheck = !classes.contains("disabled") && !classes.contains("is-loading");
// β
Final Assertion
assert !standardCheck || !classStyleCheck : "Button is active but expected to be disabled";