0
0
Selenium Pythontesting~10 mins

Why synchronization prevents flaky tests in Selenium Python - Test Your Understanding

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

Complete the code to wait for an element to be visible before clicking it.

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

wait = WebDriverWait(driver, 10)
element = wait.until(EC.[1]((By.ID, 'submit-button')))
element.click()
Drag options to blanks, or click blank then click option'
Apresence_of_element_located
Belement_to_be_clickable
Calert_is_present
Dvisibility_of_element_located
Attempts:
3 left
💡 Hint
Common Mistakes
Using presence_of_element_located which only checks if element is in DOM but not visible.
Using alert_is_present which waits for alerts, not elements.
2fill in blank
medium

Complete the code to wait until a button is clickable before clicking it.

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

wait = WebDriverWait(driver, 15)
button = wait.until(EC.[1]((By.CSS_SELECTOR, '.btn-primary')))
button.click()
Drag options to blanks, or click blank then click option'
Avisibility_of_element_located
Bpresence_of_element_located
Celement_to_be_clickable
Dframe_to_be_available_and_switch_to_it
Attempts:
3 left
💡 Hint
Common Mistakes
Using presence_of_element_located which does not guarantee clickability.
Using frame_to_be_available_and_switch_to_it which is for frames, not buttons.
3fill in blank
hard

Fix the error in the code to properly wait for an element's text to be 'Loaded'.

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

wait = WebDriverWait(driver, 20)
wait.until(EC.text_to_be_present_in_element((By.CLASS_NAME, 'status'), [1]))
Drag options to blanks, or click blank then click option'
A'Loaded'
BLoaded
C['Loaded']
DLoaded()
Attempts:
3 left
💡 Hint
Common Mistakes
Passing Loaded without quotes causes a NameError.
Passing a list or function call instead of a string.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that waits for elements with text length greater than 5.

Selenium Python
elements = driver.find_elements(By.TAG_NAME, 'p')
lengths = {el.text: len(el.text) for el in elements if len(el.text) [1] [2]
Drag options to blanks, or click blank then click option'
A>
B5
C<
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' reverses the condition.
Using 10 instead of 5 changes the filter threshold.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase texts to their lengths if length is less than 8.

Selenium Python
elements = driver.find_elements(By.CLASS_NAME, 'item')
result = { [1]: [2] for el in elements if len(el.text) [3] 8 }
Drag options to blanks, or click blank then click option'
Ael.text.upper()
Blen(el.text)
C<
Del.text.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using lower() instead of upper() changes the key format.
Using '>' instead of '<' reverses the filter condition.