0
0
Selenium Pythontesting~20 mins

CSS pseudo-classes for selection in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
CSS Pseudo-Class Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
locator
intermediate
2:00remaining
Select the first visible button using CSS pseudo-classes
You want to select the first visible
Abutton:not([hidden]):first-of-type
Bbutton:first-of-type:visible
Cbutton:first-of-type:not([hidden])
Dbutton:first-child:visible
Attempts:
2 left
💡 Hint
Remember that :visible is not a standard CSS pseudo-class and Selenium does not support it directly. Use attribute selectors to filter hidden elements.
assertion
intermediate
2:00remaining
Check if the third list item is selected using CSS pseudo-classes
You have a list with multiple
  • elements. You want to assert in Selenium that the third
  • element has the class 'selected'. Which CSS selector correctly targets this element?
  • Ali.selected:nth-of-type(3)
    Bli.selected:nth-child(3)
    Cli:nth-of-type(3).selected
    Dli:nth-child(3).selected
    Attempts:
    2 left
    💡 Hint
    nth-child counts all children, nth-of-type counts elements of the same type.
    Predict Output
    advanced
    2:00remaining
    Output of Selenium find_elements with :nth-last-child selector
    Given the following HTML structure:
    <ul>
      <li>Item 1</li>
      <li>Item 2</li>
      <li>Item 3</li>
      <li>Item 4</li>
    </ul>

    What will be the number of elements found by Selenium using the CSS selector 'li:nth-last-child(2)'?
    Selenium Python
    elements = driver.find_elements(By.CSS_SELECTOR, 'li:nth-last-child(2)')
    count = len(elements)
    print(count)
    A2
    B1
    C0
    D4
    Attempts:
    2 left
    💡 Hint
    nth-last-child(2) selects the element that is the second last child of its parent.
    🔧 Debug
    advanced
    2:00remaining
    Identify the error in this CSS selector for Selenium
    You want to select all elements that are visible and are the last child of their parent. You wrote this selector:
    input:visible:last-child

    When running Selenium, it fails to find any elements even though such elements exist. What is the problem?
    A:visible is not a valid CSS pseudo-class, causing the selector to fail
    B:last-child must come before :visible in the selector
    Cinput elements cannot be last-child in HTML
    DThe selector should use :last-of-type instead of :last-child
    Attempts:
    2 left
    💡 Hint
    Check which pseudo-classes are standard CSS and which are jQuery or Selenium extensions.
    framework
    expert
    3:00remaining
    Best practice for waiting for an element matching a CSS pseudo-class in Selenium Python
    You want to wait until the last
    child of a container with id 'main' is visible before interacting with it in Selenium Python. Which approach correctly uses CSS pseudo-classes and Selenium's WebDriverWait?
    Selenium Python
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    wait = WebDriverWait(driver, 10)
    
    # Which code snippet below is correct?
    Await.until(EC.visibility_of_element_located((By.CSS_SELECTOR, '#main div:last-child')))
    Bwait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, '#main div:last-of-type')))
    Cwait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, '#main div:last-child:visible')))
    Dwait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, '#main div:last-child:not([hidden])')))
    Attempts:
    2 left
    💡 Hint
    Use standard CSS pseudo-classes and Selenium's expected_conditions for visibility.