0
0
Selenium Pythontesting~20 mins

Explicit waits (WebDriverWait) in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Explicit Waits Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Selenium explicit wait code?
Consider the following Selenium Python code snippet using explicit wait. What will be printed?
Selenium Python
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class DummyElement:
    def __init__(self):
        self.text = "Loaded"

# Mock driver and wait for demonstration
class MockDriver:
    def find_element(self, by, value):
        return DummyElement()


driver = MockDriver()

try:
    element = WebDriverWait(driver, 5).until(
        EC.presence_of_element_located((By.ID, "my-element"))
    )
    print(element.text)
except Exception:
    print("Timeout")
AAttributeError
BTimeout
CLoaded
DNoSuchElementException
Attempts:
2 left
💡 Hint
Think about what the mock driver returns and how WebDriverWait uses it.
assertion
intermediate
1:30remaining
Which assertion correctly verifies element visibility after explicit wait?
You want to assert that an element with ID 'submit-btn' is visible after waiting explicitly. Which assertion is correct?
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)
element = wait.until(EC.visibility_of_element_located((By.ID, 'submit-btn')))
Aassert element is None
Bassert element.is_displayed() is False
Cassert element.text == 'submit-btn'
Dassert element.is_displayed() == True
Attempts:
2 left
💡 Hint
Visibility means the element is displayed on the page.
locator
advanced
2:00remaining
Which locator is best for waiting for a button with text 'Submit' to be clickable?
You want to wait explicitly until a button with visible text 'Submit' is clickable. Which locator and condition combo is best?
ABy.XPATH, "//button[text()='Submit']" with EC.element_to_be_clickable
BBy.ID, "submit" with EC.presence_of_element_located
CBy.CSS_SELECTOR, "button:contains('Submit')" with EC.element_to_be_clickable
DBy.CLASS_NAME, "submit-btn" with EC.visibility_of_element_located
Attempts:
2 left
💡 Hint
Consider which locator matches exact button text and which condition ensures clickability.
🔧 Debug
advanced
2:00remaining
Why does this explicit wait code raise TimeoutException?
This code raises TimeoutException even though the element is present. Why?
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)
wait.until(EC.visibility_of_element_located((By.ID, 'loading-spinner')))
AThe locator By.ID is invalid and causes the wait to fail
BThe element is present but not visible, so visibility_of_element_located times out
CThe wait timeout is too long causing an exception
DThe driver is not initialized before the wait
Attempts:
2 left
💡 Hint
Presence and visibility are different conditions.
framework
expert
3:00remaining
How to implement a custom explicit wait condition for element attribute value?
You want to wait until an element with ID 'status' has attribute 'data-state' equal to 'ready'. Which custom expected condition implementation is correct?
A
class attribute_value_is:
    def __init__(self, locator, attribute, value):
        self.locator = locator
        self.attribute = attribute
        self.value = value
    def __call__(self, driver):
        element = driver.find_element(*self.locator)
        return element.get_attribute(self.attribute) == self.value
B
class attribute_value_is:
    def __init__(self, locator, attribute, value):
        self.locator = locator
        self.attribute = attribute
        self.value = value
    def __call__(self, driver):
        element = driver.find_element(locator)
        return element.get_attribute(attribute) == value
C
def attribute_value_is(locator, attribute, value):
    element = driver.find_element(*locator)
    return element.get_attribute(attribute) == value
D
def attribute_value_is(locator, attribute, value):
    element = driver.find_element(locator)
    return element.get_attribute(attribute) == value
Attempts:
2 left
💡 Hint
Custom expected conditions must be callable classes with __call__ and use *self.locator.