Selenium + Python · Lesson 28 of 43
Module 28: Auto Complete & Dynamic Lists
Your task
Implement pick_matching_suggestion(items, keyword):
Write it in the editor, then press Check answer (Ctrl + Enter).
search_box = driver.find_element(By.NAME, "search")
search_box.send_keys("Selenium")
# Wait for suggestions to populate:
items = WebDriverWait(driver, 5).until(
EC.visibility_of_all_elements_located((By.CSS_SELECTOR, "ul.suggestions-list li"))
)
for item in items:
if "Selenium Python" in item.text:
item.click()
breakSearch bars with live suggestions load results via asynchronous AJAX queries. In this lesson, you will type text, wait for suggestions to render in the DOM, and select the desired item. Let's master autocomplete!
Part of the Selenium + Python course (Selenium with Python). Practice this concept live in the Selenium Online Compiler or explore our free automation practice form.
AJAX calls take a few hundred milliseconds. You must use WebDriverWait(EC.visibility_of_all_elements_located(...)) to synchronize.
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___