Challenge - 5 Problems
Expected Conditions Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of waiting for element visibility
What will be the output of this Selenium Python code snippet when the element with id 'submit-btn' becomes visible within 10 seconds?
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 # Assume driver is a valid WebDriver instance wait = WebDriverWait(driver, 10) element = wait.until(EC.visibility_of_element_located((By.ID, 'submit-btn'))) print(element.tag_name)
Attempts:
2 left
💡 Hint
Think about what visibility_of_element_located returns when the element appears.
✗ Incorrect
The wait.until with visibility_of_element_located returns the WebElement once it is visible. Printing element.tag_name outputs the tag name, such as 'button'.
❓ assertion
intermediate2:00remaining
Correct assertion for element invisibility
Which assertion correctly verifies that an element with class name 'loading-spinner' is no longer visible using Selenium's expected conditions?
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, 15) # Which assertion below is correct?
Attempts:
2 left
💡 Hint
Look for the condition that waits for the element to disappear or become invisible.
✗ Incorrect
invisibility_of_element_located waits until the element is either not present or not visible. This is the correct way to assert invisibility.
🔧 Debug
advanced2:00remaining
Identify the error in expected condition usage
What error will this Selenium Python code raise when executed?
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, 5) # Incorrect usage of expected condition wait.until(EC.element_to_be_clickable(By.ID, 'login'))
Attempts:
2 left
💡 Hint
Check how locators are passed to expected conditions.
✗ Incorrect
expected_conditions functions require a single locator tuple like (By.ID, 'login'). Passing By.ID and 'login' as separate arguments causes a TypeError.
🧠 Conceptual
advanced2:00remaining
Understanding expected condition behavior
Which statement best describes the behavior of the expected condition 'presence_of_element_located' in Selenium?
Attempts:
2 left
💡 Hint
Think about presence vs visibility.
✗ Incorrect
presence_of_element_located waits for the element to exist in the page's HTML structure (DOM), but does not require it to be visible.
❓ framework
expert3:00remaining
Best practice for waiting for multiple conditions
You want to wait until either an element with id 'success-msg' is visible or an element with id 'error-msg' is visible, whichever appears first. Which Selenium Python code snippet correctly implements this using expected conditions?
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, 20) # Choose the correct code:
Attempts:
2 left
💡 Hint
Look for the expected condition that waits for any one of multiple conditions.
✗ Incorrect
EC.any_of waits until any one of the given expected conditions is true. EC.or_ does not exist. Using Python 'or' or 'and' operators directly will not work as expected.