Bird
Raised Fist0
Selenium Pythontesting~20 mins

Find element by tag name in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Tag Name Locator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ locator
intermediate
2:00remaining
Locate the first
Which Selenium Python code snippet correctly finds the first
Aelement = driver.find_element(By.ID, 'button')
Belement = driver.find_element_by_tag('button')
Celement = driver.find_element(By.CLASS_NAME, 'button')
Delement = driver.find_element(By.TAG_NAME, 'button')
Attempts:
2 left
💡 Hint
Use the correct Selenium method and locator strategy for tag name.
❓ assertion
intermediate
2:00remaining
Assert the text of the first

element

Given the code below, which assertion correctly checks that the first

element's text is exactly 'Welcome'?

Selenium Python
element = driver.find_element(By.TAG_NAME, 'h1')
text = element.text
Aassert text.contains('Welcome')
Bassert text == 'Welcome'
Cassert text.equals('Welcome')
Dassert text is 'Welcome'
Attempts:
2 left
💡 Hint
Use Python string equality to check exact match.
❓ Predict Output
advanced
2:00remaining
Output of finding multiple elements by tag name
What is the output of the following code snippet if the page contains exactly 3
  • elements?
  • Selenium Python
    elements = driver.find_elements(By.TAG_NAME, 'li')
    print(len(elements))
    A3
    B1
    C0
    DTypeError
    Attempts:
    2 left
    💡 Hint
    find_elements returns a list of matching elements.
    🔧 Debug
    advanced
    2:00remaining
    Identify the error in finding element by tag name
    What error will the following code raise if no
    element exists on the page?
    Selenium Python
    element = driver.find_element(By.TAG_NAME, 'footer')
    ATypeError
    BAttributeError
    Cselenium.common.exceptions.NoSuchElementException
    DIndexError
    Attempts:
    2 left
    💡 Hint
    find_element raises an exception if no element is found.
    ❓ framework
    expert
    3:00remaining
    Best practice for waiting for an element by tag name
    Which Selenium Python code snippet correctly waits up to 10 seconds for the first
    Aelement = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.TAG_NAME, 'nav')))
    B
    driver.implicitly_wait(10)
    element = driver.find_element(By.TAG_NAME, 'nav')
    Celement = driver.find_element(By.TAG_NAME, 'nav')
    D
    time.sleep(10)
    element = driver.find_element(By.TAG_NAME, 'nav')
    Attempts:
    2 left
    💡 Hint
    Use explicit waits with expected conditions for reliable waiting.

    Practice

    (1/5)
    1. What does find_element(By.TAG_NAME, 'button') do in Selenium Python?
    easy
    A. Finds all <button> elements on the page
    B. Finds elements by their ID 'button'
    C. Finds elements by their class name 'button'
    D. Finds the first <button> element on the page

    Solution

    1. Step 1: Understand the method used

      The method find_element returns the first matching element found.
    2. Step 2: Understand the locator type

      Using By.TAG_NAME with 'button' searches for the first <button> tag element.
    3. Final Answer:

      Finds the first <button> element on the page -> Option D
    4. Quick Check:

      find_element + TAG_NAME = first matching tag element [OK]
    Hint: find_element + TAG_NAME finds only the first matching tag [OK]
    Common Mistakes:
    • Confusing find_element with find_elements
    • Using class name or ID instead of tag name
    • Expecting all elements instead of first only
    2. Which of the following is the correct syntax to find all p elements using Selenium Python?
    easy
    A. driver.find_element_by_tag_name('p')
    B. driver.find_element(By.TAG_NAME, 'p')
    C. driver.find_elements(By.TAG_NAME, 'p')
    D. driver.find_elements_by_class_name('p')

    Solution

    1. Step 1: Identify method for multiple elements

      To get all matching elements, use find_elements (plural).
    2. Step 2: Use correct locator for tag name

      Use By.TAG_NAME with the tag string 'p'.
    3. Final Answer:

      driver.find_elements(By.TAG_NAME, 'p') -> Option C
    4. Quick Check:

      find_elements + TAG_NAME = all matching tags [OK]
    Hint: Use find_elements (plural) to get all elements by tag [OK]
    Common Mistakes:
    • Using find_element instead of find_elements
    • Using deprecated find_element_by_tag_name syntax
    • Confusing class name locator with tag name
    3. Given the HTML:
    <div>
      <button>Click</button>
      <button>Submit</button>
    </div>

    What will driver.find_element(By.TAG_NAME, 'button').text return?
    medium
    A. "ClickSubmit"
    B. "Click"
    C. "Submit"
    D. Throws NoSuchElementException

    Solution

    1. Step 1: Understand find_element behavior

      It returns the first matching element by tag name, which is the first <button> with text "Click".
    2. Step 2: Access the text property

      The .text attribute returns the visible text inside that element, which is "Click".
    3. Final Answer:

      "Click" -> Option B
    4. Quick Check:

      First button text = "Click" [OK]
    Hint: find_element returns first tag; .text shows its text content [OK]
    Common Mistakes:
    • Assuming it returns all buttons' text combined
    • Confusing find_element with find_elements
    • Expecting an exception when element exists
    4. You wrote this code:
    element = driver.find_elements(By.TAG_NAME, 'img')

    But you get an error when trying element.click(). What is the problem?
    medium
    A. find_elements returns a list, not a single element
    B. The tag name 'img' is invalid
    C. click() cannot be used on images
    D. You must use find_element instead of find_elements

    Solution

    1. Step 1: Understand return type of find_elements

      find_elements returns a list of WebElements, not a single element.
    2. Step 2: Identify why click() fails

      Calling click() on a list causes an error because lists don't have click method.
    3. Final Answer:

      find_elements returns a list, not a single element -> Option A
    4. Quick Check:

      find_elements = list, cannot call click() directly [OK]
    Hint: find_elements returns list; call click() on list item, not list [OK]
    Common Mistakes:
    • Calling click() on list instead of element
    • Confusing find_element and find_elements return types
    • Assuming all tags support click() without checking
    5. You want to click the second button on a page. Which code correctly finds and clicks it using tag name?
    hard
    A. buttons = driver.find_elements(By.TAG_NAME, 'button') buttons[1].click()
    B. button = driver.find_element(By.TAG_NAME, 'button') button[1].click()
    C. button = driver.find_elements(By.TAG_NAME, 'button') button.click()
    D. buttons = driver.find_element(By.TAG_NAME, 'button') buttons.click()

    Solution

    1. Step 1: Use find_elements to get all buttons

      Use find_elements(By.TAG_NAME, 'button') to get a list of all button elements.
    2. Step 2: Access second button and click

      Index 1 accesses the second button (0-based index), then call click() on it.
    3. Final Answer:

      buttons = driver.find_elements(By.TAG_NAME, 'button') buttons[1].click() -> Option A
    4. Quick Check:

      find_elements + index + click = correct usage [OK]
    Hint: Use find_elements, index second item, then click [OK]
    Common Mistakes:
    • Using find_element and indexing it like a list
    • Calling click() on list instead of element
    • Using wrong index (like 2 instead of 1 for second element)
    Recommended

    Ready to prove it?

    Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

    10 questions~5 mineasy hard