0
0
Selenium Pythontesting~20 mins

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

Choose your learning style9 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.