Challenge - 5 Problems
CSS Pseudo-Class Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ locator
intermediate2:00remaining
Select the first visible button using CSS pseudo-classes
You want to select the first 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.
✗ Incorrect
CSS does not have a :visible pseudo-class. Selenium uses attribute selectors like [hidden] to filter elements. Option C correctly selects the first button that is not hidden.
❓ assertion
intermediate2: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?
Attempts:
2 left
💡 Hint
nth-child counts all children, nth-of-type counts elements of the same type.
✗ Incorrect
Option D selects the third child
❓ Predict Output
advanced2:00remaining
Output of Selenium find_elements with :nth-last-child selector
Given the following HTML structure:
What will be the number of elements found by Selenium using the CSS selector 'li:nth-last-child(2)'?
<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)
Attempts:
2 left
💡 Hint
nth-last-child(2) selects the element that is the second last child of its parent.
✗ Incorrect
Only the third
- . So only one element matches.
🔧 Debug
advanced2: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:
When running Selenium, it fails to find any elements even though such elements exist. What is the problem?
input:visible:last-child
When running Selenium, it fails to find any elements even though such elements exist. What is the problem?
Attempts:
2 left
💡 Hint
Check which pseudo-classes are standard CSS and which are jQuery or Selenium extensions.
✗ Incorrect
:visible is not a standard CSS pseudo-class and is not supported by Selenium CSS selectors. This causes the selector to fail.
❓ framework
expert3: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?
Attempts:
2 left
💡 Hint
Use standard CSS pseudo-classes and Selenium's expected_conditions for visibility.
✗ Incorrect
Option A correctly uses the standard CSS pseudo-class :last-child and Selenium's visibility_of_element_located to wait for visibility.
Option A uses :visible which is not a CSS pseudo-class. Option A uses :not([hidden]) which may work but visibility_of_element_located is more reliable.