Selenium • Python
Selenium Explicit Wait Snippet (Python)
Python Selenium snippet demonstrating Explicit Waits. Wait for an element to be clickable before interacting.
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# Wait up to 10 seconds for the element to be clickable
element = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.ID, 'submit-button'))
)
element.click()
How it works
Using Explicit Waits is best practice in Selenium. This code waits up to 10 seconds for an element with ID 'submit-button' to become clickable before executing the click command.
Tired of writing Selenium tests manually? GenTestCase AI generates them in seconds directly from your PRDs or Jira tickets.
Tired of writing boilerplate test code?
GenTestCase uses AI to automatically generate thousands of test cases and automation scripts directly from your requirements.
Start Generating for Free