Selenium + Python · Lesson 37 of 43
Module 37: Selenium Exception Handling
Your task
Implement is_element_present(driver, locator):
Write it in the editor, then press Check answer (Ctrl + Enter).
from selenium.common.exceptions import NoSuchElementException
def check_element_exists(driver, locator: tuple) -> bool:
try:
driver.find_element(*locator)
return True
except NoSuchElementException:
return FalseKnowing how to quickly diagnose exceptions makes you a 10x faster automation engineer. In this lesson, you will master handling NoSuchElementException, TimeoutException, and ElementClickInterceptedException cleanly. Let's troubleshoot exceptions!
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.
From selenium.common.exceptions (e.g. from selenium.common.exceptions import NoSuchElementException, TimeoutException).
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___