Date Picker (Calendar)
Strategy: open the calendar, move to the right month, click the day.
python
from datetime import date
from selenium.webdriver.common.by import By
def pick_date(driver, wait, target: date):
driver.find_element(By.ID, "datepicker").click()
while True:
month_year = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".ui-datepicker-title"))).text
if month_year == target.strftime("%B %Y"):
break
driver.find_element(By.CSS_SELECTOR, ".ui-datepicker-next").click()
driver.find_element(By.XPATH, f"//td[@data-handler='selectDay']/a[text()='{target.day}']").click()
pick_date(driver, wait, date(2026, 12, 25))
assert driver.find_element(By.ID, "datepicker").get_attribute("value") == "12/25/2026"
Shortcut: If the input accepts typing, send_keys("12/25/2026") is simpler. Use the calendar flow only when typing is blocked.
Autocomplete Suggestions
python
box = driver.find_element(By.ID, "search")
box.send_keys("sele")
suggestions = wait.until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, ".suggestion-item")))
texts = [s.text for s in suggestions]
assert any("selenium" in t.lower() for t in texts)
for s in suggestions:
if s.text.lower() == "selenium python":
s.click()
break
Sliders
python
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
slider = driver.find_element(By.CSS_SELECTOR, "input[type='range']")
# 1. keyboard: reliable
slider.send_keys(Keys.ARROW_RIGHT * 5)
# 2. mouse drag
ActionChains(driver).click_and_hold(slider).move_by_offset(40, 0).release().perform()
# 3. JavaScript for exact values
driver.execute_script("arguments[0].value = 75; arguments[0].dispatchEvent(new Event('input', {bubbles:true}));", slider)
Toast Messages and Spinners
Short-lived messages disappear quickly. Wait for them right after the action, and read the text immediately.
python
driver.find_element(By.ID, "save").click()
toast = WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".toast-message")))
assert "Saved" in toast.text
WebDriverWait(driver, 10).until(EC.invisibility_of_element_located((By.CSS_SELECTOR, ".spinner")))
SVG Elements
SVG tags do not work with normal XPath names. Use name() or local-name():
python
bars = driver.find_elements(By.XPATH, "//*[name()='svg']//*[name()='rect']")
dots = driver.find_elements(By.CSS_SELECTOR, "svg circle") # CSS works fine
Canvas and Maps
The content of <canvas> is a picture, so Selenium cannot see inside. Test the data behind it (API, JavaScript variables) or use visual testing tools.
CAPTCHA and Two-Factor Login
Captcha is made to stop automation. Do not try to break captchas. Ask for a test environment with captcha turned off or a special test key (Google provides test keys that always pass). For 2FA, use a test account with a fixed code or generate a one-time password in your test.
python
# pip install pyotp
import pyotp
totp = pyotp.TOTP(os.environ["TEST_ACCOUNT_2FA_SECRET"])
driver.find_element(By.ID, "otp").send_keys(totp.now())
Elements Created After Scrolling (Lazy Load)
python
def scroll_until(driver, locator, max_scrolls=20):
for _ in range(max_scrolls):
found = driver.find_elements(*locator)
if found:
return found[0]
driver.execute_script("window.scrollBy(0, 800);")
time.sleep(0.5)
raise AssertionError(f"{locator} not found after scrolling")
Cookie Banners
python
def accept_cookies_if_present(driver):
buttons = driver.find_elements(By.CSS_SELECTOR, "#onetrust-accept-btn-handler")
if buttons and buttons[0].is_displayed():
buttons[0].click()
Conclusion
Use the right strategy for each widget: typed dates or calendar navigation, waits for suggestions, keyboard for sliders, name() for SVG and never fight captcha: use test settings.
Quick Summary: Wait for the widget, act like a user, verify the result; avoid captcha with test config.