28. Search Suggestions & Auto-Complete Lists

Handling Auto-Complete Suggestions

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()
break

Task

  • Implement pick_matching_suggestion(items, keyword):
  • 1. Loop through items.
  • 2. If keyword in item.text, item.click() and return True.
  • 3. Return False if none matched.
πŸ’‘Common doubts
Did you like the problem?
Lesson 28 of 43
Python
Loading code editor…
Next