Skip to content
CodeKruPro

Wait until a button is clickable

Automation taskMediumAsked in: Accenture, BrowserStack, Capgemini, Cognizant, Infosys, TCS, Wipro

Asked as: "The Save button is disabled until the form loads. How do you click it at the right moment?" Wait until it is clickable, which here means visible and enabled, then click. Here you wait until the left-click button is clickable, click it and read its new text.

Explicit Wait - Element Clickable

Explicit Wait - elementToBeClickable

elementToBeClickable waits until an element is both visible and enabled (clickable). This is useful for buttons that may take time to become active.

Task:

  1. Navigate to https://testkru.com/Elements/Buttons
  2. Use WebDriverWait to wait for the leftClick button to be clickable
  3. Click the button
  4. Print the button text after clicking

Expected output:

Button is clickable: true
After click: I was left-clicked!