πŸ’‘ If you like this website, please share it with your friends and network! πŸš€
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();