Challenge - 5 Problems
Class Name Locator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ locator
intermediate2:00remaining
Identify the correct Selenium locator for class name
Which of the following Selenium Python code snippets correctly finds an element by its class name
btn-primary?Attempts:
2 left
💡 Hint
Use the modern Selenium syntax with By.CLASS_NAME for class selectors.
✗ Incorrect
Option A uses the correct modern Selenium syntax with By.CLASS_NAME. Option A uses an invalid locator type 'By.CLASS'. Option A uses deprecated syntax no longer supported in Selenium 4+. Option A uses CSS selector which works but is not the direct class name locator.
❓ Predict Output
intermediate2:00remaining
Output of Selenium find_element by class name with multiple matches
Given the HTML below, what will
driver.find_element(By.CLASS_NAME, "item") return?Selenium Python
<div class="item">First</div> <div class="item">Second</div> <div class="item">Third</div>
Attempts:
2 left
💡 Hint
find_element returns only one element, not a list.
✗ Incorrect
find_element returns the first matching element found in the DOM. To get all matching elements, find_elements should be used.
❓ assertion
advanced2:00remaining
Correct assertion to verify element text found by class name
You found an element by class name
message. Which assertion correctly verifies its text is exactly Success?Selenium Python
element = driver.find_element(By.CLASS_NAME, "message")
text = element.textAttempts:
2 left
💡 Hint
Use Python's equality operator to compare strings.
✗ Incorrect
Option B correctly uses Python's equality operator '==' to compare strings. Option B is invalid syntax. Option B uses 'is' which checks identity, not equality. Option B uses a method not available on Python strings.
🔧 Debug
advanced2:00remaining
Identify the error in Selenium code using class name locator
What error will this code raise?
element = driver.find_element(By.CLASS_NAME, "btn primary")
Selenium Python
from selenium.webdriver.common.by import By # Attempt to find element by class name with space element = driver.find_element(By.CLASS_NAME, "btn primary")
Attempts:
2 left
💡 Hint
Class name locators cannot contain spaces because they represent a single class.
✗ Incorrect
Using a class name with spaces is invalid because class names cannot contain spaces. Selenium raises InvalidSelectorException for this.
❓ framework
expert2:00remaining
Best practice for waiting for element by class name in Selenium
Which code snippet correctly waits up to 10 seconds for an element with class name
loading-complete to appear before proceeding?Attempts:
2 left
💡 Hint
Explicit waits are preferred for waiting specific conditions.
✗ Incorrect
Option A uses explicit wait with WebDriverWait and expected_conditions, which waits up to 10 seconds for the element. Option A blindly waits 10 seconds regardless of element presence. Option A does not wait at all. Option A sets implicit wait but explicit wait is more reliable for specific conditions.