0
0
Selenium Pythontesting~10 mins

Custom wait 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 import the WebDriverWait class from selenium.

Selenium Python
from selenium.webdriver.support.ui import [1]
Drag options to blanks, or click blank then click option'
AExpectedConditions
BWebDriverWait
CBy
Dwebdriver
Attempts:
3 left
💡 Hint
Common Mistakes
Importing ExpectedConditions instead of WebDriverWait
Importing By which is for locating elements
Importing webdriver which is for browser control
2fill in blank
medium

Complete the code to wait until an element with id 'submit' is clickable.

Selenium Python
wait = WebDriverWait(driver, 10)
element = wait.until([1].element_to_be_clickable((By.ID, 'submit')))
Drag options to blanks, or click blank then click option'
Awebdriver
Btime
Cexpected_conditions
DBy
Attempts:
3 left
💡 Hint
Common Mistakes
Using webdriver instead of expected_conditions
Using By which is for locating elements
Using time which is unrelated
3fill in blank
hard

Fix the error in the custom wait condition function to check if an element's text equals 'Done'.

Selenium Python
def wait_for_text(driver):
    element = driver.find_element(By.ID, 'status')
    return element.text [1] 'Done'
Drag options to blanks, or click blank then click option'
A==
B!=
C=
Dis
Attempts:
3 left
💡 Hint
Common Mistakes
Using single equals = which is assignment, not comparison
Using != which checks inequality
Using is which checks identity, not string equality
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps element ids to their text if the text length is greater than 3.

Selenium Python
texts = {id: driver.find_element(By.ID, id).text for id in ids if len(driver.find_element(By.ID, id).text) [1] [2]
Drag options to blanks, or click blank then click option'
A>
B3
C<
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of >
Using == which checks equality, not length condition
5fill in blank
hard

Fill all three blanks to create a custom wait that returns True if the element with id 'result' contains text longer than 5 characters.

Selenium Python
def wait_for_result(driver):
    element = driver.find_element(By.ID, [1])
    return len(element.text) [2] [3]
Drag options to blanks, or click blank then click option'
A'result'
B>
C5
D'status'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong element id like 'status'
Using < or == instead of >
Using wrong number instead of 5