0
0
Selenium Pythontesting~10 mins

Custom expected conditions in Selenium Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a custom expected condition that waits for an element to be visible.

Selenium Python
class element_visible:
    def __init__(self, locator):
        self.locator = locator

    def __call__(self, driver):
        element = driver.find_element(*self.locator)
        return element if element.is_displayed() [1] None
Drag options to blanks, or click blank then click option'
Aelse
Bor
Cand
Dif
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'if' instead of 'or' causes syntax errors.
Returning the element without checking visibility.
Returning True/False instead of element or None.
2fill in blank
medium

Complete the code to define a custom expected condition that waits for the page title to contain a specific word.

Selenium Python
class title_contains_word:
    def __init__(self, word):
        self.word = word

    def __call__(self, driver):
        return self.word in driver.title [1] False
Drag options to blanks, or click blank then click option'
Aand
Bor
Cif
Delse
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'or False' which always returns True.
Returning the expression without ensuring a boolean result.
Using 'if' or 'else' incorrectly in a return statement.
3fill in blank
hard

Fix the error in the custom expected condition that waits for an element's text to equal a given value.

Selenium Python
class text_to_be_equal:
    def __init__(self, locator, text):
        self.locator = locator
        self.text = text

    def __call__(self, driver):
        element = driver.find_element(*self.locator)
        return element.text == self.text [1] element
Drag options to blanks, or click blank then click option'
Aelse
Bor
Cif
Dand
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'or element' which returns element even if text does not match.
Returning True/False instead of element or False.
Using 'if' or 'else' incorrectly in return.
4fill in blank
hard

Fill both blanks to create a custom expected condition that waits for an element to be clickable.

Selenium Python
from selenium.webdriver.support import expected_conditions as EC

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

    def __call__(self, driver):
        element = driver.find_element(*self.locator)
        return element.is_enabled() [1] element.is_displayed() [2] element
Drag options to blanks, or click blank then click option'
Aand
Bor
Cif
Delse
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'or' which returns element if only one condition is true.
Using 'if' or 'else' in return statement.
Returning True/False instead of element or None.
5fill in blank
hard

Fill all three blanks to create a custom expected condition that waits for an element's attribute to have a specific value.

Selenium Python
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)
        attr_value = element.get_attribute([1])
        return attr_value == [2] [3] element
Drag options to blanks, or click blank then click option'
Aself.attribute
Bself.value
Cand
Dor
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names for attribute or value.
Using 'or' which returns element even if values don't match.
Returning True/False instead of element or None.