0
0
Selenium Pythontesting~20 mins

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

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Wait Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Why avoid using time.sleep() in Selenium tests?

Which of the following is the best reason to avoid using time.sleep() in Selenium tests?

AIt automatically retries failed actions until success, making tests flaky.
BIt waits only for specific elements to appear, improving test speed.
CIt causes tests to wait a fixed time even if the page is ready earlier, slowing down tests.
DIt dynamically adjusts wait time based on network speed.
Attempts:
2 left
💡 Hint

Think about what happens if the page loads faster than the sleep time.

Predict Output
intermediate
2:00remaining
Output of Selenium wait code snippet

What will be the output of this Selenium Python code snippet?

Selenium Python
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class DummyDriver:
    def find_element(self, by, value):
        raise Exception('Element not found')

try:
    driver = DummyDriver()
    wait = WebDriverWait(driver, 3)
    wait.until(EC.presence_of_element_located((By.ID, 'myid')))
    print('Element found')
except Exception as e:
    print(f'Error: {e}')
AElement found
BTimeoutException
CSyntaxError
DError: Element not found
Attempts:
2 left
💡 Hint

Consider what happens when find_element always raises an exception.

assertion
advanced
2:00remaining
Correct assertion for element visibility after wait

Which assertion correctly verifies that an element is visible after using an explicit wait in Selenium?

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)
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, '.my-class')))

# Which assertion is correct here?
Aassert driver.find_element(By.CSS_SELECTOR, '.my-class').is_enabled()
Bassert driver.find_element(By.CSS_SELECTOR, '.my-class').is_displayed()
Cassert driver.find_element(By.CSS_SELECTOR, '.my-class').text == ''
Dassert driver.find_element(By.CSS_SELECTOR, '.my-class') is None
Attempts:
2 left
💡 Hint

Visibility means the element is shown on the page.

🔧 Debug
advanced
2:00remaining
Identify the problem with this wait usage

What is the main problem with this Selenium Python code snippet?

Selenium Python
import time
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, 5)
wait.until(EC.presence_of_element_located((By.ID, 'submit-btn')))
time.sleep(3)
driver.find_element(By.ID, 'submit-btn').click()
AUsing time.sleep() after the explicit wait causes unnecessary delay.
BThe wait timeout is too long and causes a timeout error.
CThe locator By.ID is invalid and causes NoSuchElementException.
DThe click() method is called before the element is present.
Attempts:
2 left
💡 Hint

Think about the purpose of explicit waits and fixed sleeps.

framework
expert
2:30remaining
Best practice for waiting in Selenium test framework

In a Selenium test framework, which approach best improves test reliability and speed when waiting for elements?

AUse explicit waits with Expected Conditions targeting specific elements and avoid fixed sleeps.
BUse only time.sleep() with long fixed delays to ensure all elements load.
CUse implicit waits set once globally and never use explicit waits.
DAvoid any waits and rely on retrying failed tests manually.
Attempts:
2 left
💡 Hint

Consider how to wait efficiently and reliably for elements.