0
0
Selenium Pythontesting~10 mins

Time.sleep vs proper waits in Selenium Python - Interactive Practice

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

Complete the code to pause the test for 5 seconds using time.sleep.

Selenium Python
import time

time.[1](5)
Drag options to blanks, or click blank then click option'
Adelay
Bsleep
Cpause
Dwait
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'wait' or 'pause' which are not functions in the time module.
Forgetting to import the time module.
2fill in blank
medium

Complete the code to wait until an element with ID 'submit' is clickable using Selenium's WebDriverWait.

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)
wait.until(EC.[1]((By.ID, 'submit')))
Drag options to blanks, or click blank then click option'
Apresence_of_element_located
Balert_is_present
Cvisibility_of_element_located
Delement_to_be_clickable
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'presence_of_element_located' which only checks if element is in DOM, not clickable.
Using 'alert_is_present' which is unrelated to element clicking.
3fill in blank
hard

Fix the error in the code to properly wait for an element with class name 'loading' to disappear.

Selenium Python
wait = WebDriverWait(driver, 15)
wait.until(EC.[1]((By.CLASS_NAME, 'loading')))
Drag options to blanks, or click blank then click option'
Ainvisibility_of_element_located
Bpresence_of_element_located
Cvisibility_of_element_located
Delement_to_be_clickable
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'presence_of_element_located' which waits for presence, not disappearance.
Using 'visibility_of_element_located' which waits for visibility, opposite of what is needed.
4fill in blank
hard

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

Selenium Python
elements_text = {el.get_attribute('id'): el.text for el in driver.find_elements(By.TAG_NAME, 'div') if len(el.[1]) [2] 3}
Drag options to blanks, or click blank then click option'
Atext
B>
C<
Dget_attribute('text')
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get_attribute('text')' which is not a valid attribute.
Using '<' instead of '>' which filters shorter texts.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase element IDs to their text only if the text contains the letter 'a'.

Selenium Python
elements_dict = {el.get_attribute([1]).[2](): el.text for el in driver.find_elements(By.CLASS_NAME, 'item') if 'a' [3] el.text}
Drag options to blanks, or click blank then click option'
A'id'
Bupper
Cin
Dcontains
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'contains' which is not a Python operator.
Forgetting to quote 'id' as a string.