Back to All Scenarios
Scenario 18 of 100
Synchronization
Beginner
Wait for a Button to be Clickable
πScenario Overview
Wait for a Button to be Clickable
Key Takeaways & Cheat Sheet
- βConfirm the element is present in the DOM
- βConfirm the element is visible on the rendered UI viewport
- βConfirm the element is enabled (does not contain disabled="disabled")
- βApply ExpectedConditions.elementToBeClickable for dynamic synchronization
Short Direct Answer
An element must satisfy three conditions before a click can succeed: it must be present in the HTML DOM, visible on the UI, and enabled (not disabled). Using the `elementToBeClickable` condition in `WebDriverWait` automatically handles all three checks and returns the element as soon as it matches.
β οΈ Senior Warning (Red Flag)
Avoid using presenceOfElementLocated when you intend to click. Presence only means it is in the HTML code; it could still be hidden or disabled, causing click failures.
π‘ STAR Deep Dive Explanation & Pro Tip
Explicit waits are highly optimized. If the button becomes clickable in 200ms, the test proceeds instantly, avoiding static timeouts.
SeleniumAutomation.java
Selenium 4 + Java// β
Wait explicitly for button to be clickable
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
WebElement saveButton = wait.until(
ExpectedConditions.elementToBeClickable(By.id("save-profile-btn"))
);
saveButton.click();