0
0
Selenium Pythontesting~20 mins

Custom expected conditions in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Custom Expected Conditions 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 custom expected condition?
Consider the following Selenium custom expected condition class. What will be the output of the test assertion if the element with id 'status' has text 'Ready'?
Selenium Python
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

class element_text_is_ready:
    def __init__(self, locator):
        self.locator = locator

    def __call__(self, driver):
        element = driver.find_element(*self.locator)
        return element.text == 'Ready'

# Usage example:
# wait = WebDriverWait(driver, 10)
# result = wait.until(element_text_is_ready((By.ID, 'status')))
# print(result)
ATimeoutException
BFalse
CTrue
DAttributeError
Attempts:
2 left
💡 Hint
Think about what the __call__ method returns when the element text matches 'Ready'.
assertion
intermediate
2:00remaining
Which assertion correctly verifies a custom expected condition?
You have a custom expected condition that returns the element if visible, else False. Which assertion correctly checks that the element is found and visible?
Selenium Python
class element_is_visible:
    def __init__(self, locator):
        self.locator = locator

    def __call__(self, driver):
        element = driver.find_element(*self.locator)
        return element if element.is_displayed() else False

# wait = WebDriverWait(driver, 10)
# result = wait.until(element_is_visible((By.CSS_SELECTOR, '.btn')))
Aassert result == False
Bassert result is not False
Cassert result is None
Dassert result == True
Attempts:
2 left
💡 Hint
Remember the custom condition returns the element or False, not a boolean True.
🔧 Debug
advanced
2:00remaining
Why does this custom expected condition cause a TimeoutException?
This custom expected condition is intended to wait until an element's attribute 'data-status' equals 'complete'. Why does it always cause a TimeoutException?
Selenium Python
class attribute_value_is_complete:
    def __init__(self, locator):
        self.locator = locator

    def __call__(self, driver):
        element = driver.find_element(*self.locator)
        return element.get_attribute('data-status') == 'complete'

# wait = WebDriverWait(driver, 5)
# wait.until(attribute_value_is_complete((By.ID, 'task')))
AAttribute 'data-status' does not exist on element
BTimeout is too short to wait for condition
CThe __call__ method returns None instead of boolean
DIncorrect unpacking of locator tuple in find_element
Attempts:
2 left
💡 Hint
Check how the locator tuple is used in find_element.
framework
advanced
2:00remaining
Which custom expected condition class correctly waits for an element's CSS class to include 'active'?
Select the class that correctly implements a custom expected condition to wait until the element's class attribute contains the word 'active'.
A
class element_has_active_class:
    def __init__(self, locator):
        self.locator = locator
    def __call__(self, driver):
        element = driver.find_element(*self.locator)
        return 'active' in element.get_attribute('class')
B
class element_has_active_class:
    def __init__(self, locator):
        self.locator = locator
    def __call__(self, driver):
        element = driver.find_element(self.locator)
        return element.get_attribute('class') == 'active'
C
class element_has_active_class:
    def __init__(self, locator):
        self.locator = locator
    def __call__(self, driver):
        element = driver.find_element(*self.locator)
        return element.get_attribute('class').contains('active')
D
class element_has_active_class:
    def __init__(self, locator):
        self.locator = locator
    def __call__(self, driver):
        element = driver.find_element(*self.locator)
        return element.get_attribute('class') == ['active']
Attempts:
2 left
💡 Hint
Check correct locator unpacking and string containment syntax in Python.
🧠 Conceptual
expert
2:00remaining
What is the main advantage of using custom expected conditions in Selenium tests?
Why should testers create custom expected conditions instead of only using built-in ones?
AThey allow waiting for complex or specific conditions not covered by built-in ones
BThey reduce test execution time by skipping waits
CThey automatically fix flaky tests without code changes
DThey replace the need for assertions in tests
Attempts:
2 left
💡 Hint
Think about flexibility and test reliability.