Recall & Review
beginner
What does the Selenium method
find_element_by_tag_name do?It finds the first web element on the page that matches the given HTML tag name, like
<button> or <input>.Click to reveal answer
beginner
How do you find the first
<h1> element on a page using Selenium in Python?Use
driver.find_element(By.TAG_NAME, 'h1') after importing By from selenium.webdriver.common.by.Click to reveal answer
intermediate
Why is it better to use
By.TAG_NAME instead of the older find_element_by_tag_name method?Because
By.TAG_NAME is the current recommended way in Selenium 4+, making your code more future-proof and compatible with updates.Click to reveal answer
beginner
What happens if
find_element(By.TAG_NAME, 'tag') does not find any matching element?Selenium raises a
NoSuchElementException, meaning no element with that tag name exists on the page.Click to reveal answer
beginner
Can
find_element(By.TAG_NAME, 'tag') find multiple elements?No, it finds only the first matching element. To find all matching elements, use
find_elements(By.TAG_NAME, 'tag').Click to reveal answer
Which Selenium method finds the first element by tag name in Python?
✗ Incorrect
The correct method to find by tag name is find_element with By.TAG_NAME.
What exception is raised if no element is found by tag name?
✗ Incorrect
NoSuchElementException is raised when no matching element is found.
To find all
<div> elements on a page, which method should you use?✗ Incorrect
find_elements returns all matching elements, not just the first.
Why is using
By.TAG_NAME preferred over find_element_by_tag_name?✗ Incorrect
By.TAG_NAME is the modern, recommended way to locate elements by tag.
Which tag name would you use to find the main heading of a webpage?
✗ Incorrect
The
tag is used for main headings.
Explain how to find an element by tag name using Selenium in Python.
Think about the modern Selenium syntax and error handling.
You got /3 concepts.
Describe the difference between find_element and find_elements when using tag name locator.
Consider what happens when multiple elements match or none match.
You got /4 concepts.