Bird
Raised Fist0
Selenium Pythontesting~20 mins

Expected conditions in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Expected Conditions Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of waiting for element visibility
What will be the output of this Selenium Python code snippet when the element with id 'submit-btn' becomes visible within 10 seconds?
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

# Assume driver is a valid WebDriver instance
wait = WebDriverWait(driver, 10)
element = wait.until(EC.visibility_of_element_located((By.ID, 'submit-btn')))
print(element.tag_name)
APrints the tag name of the element, e.g., 'button'
BRaises TimeoutException immediately
CPrints None
DRaises NoSuchElementException
Attempts:
2 left
💡 Hint
Think about what visibility_of_element_located returns when the element appears.
❓ assertion
intermediate
2:00remaining
Correct assertion for element invisibility
Which assertion correctly verifies that an element with class name 'loading-spinner' is no longer visible using Selenium's expected conditions?
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, 15)

# Which assertion below is correct?
Aassert wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'loading-spinner')))
Bassert wait.until(EC.visibility_of_element_located((By.CLASS_NAME, 'loading-spinner')))
Cassert wait.until(EC.element_to_be_clickable((By.CLASS_NAME, 'loading-spinner')))
Dassert wait.until(EC.invisibility_of_element_located((By.CLASS_NAME, 'loading-spinner')))
Attempts:
2 left
💡 Hint
Look for the condition that waits for the element to disappear or become invisible.
🔧 Debug
advanced
2:00remaining
Identify the error in expected condition usage
What error will this Selenium Python code raise when executed?
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, 5)
# Incorrect usage of expected condition
wait.until(EC.element_to_be_clickable(By.ID, 'login'))
ATypeError because expected_conditions expect a tuple locator, not separate arguments
BTimeoutException because element never becomes clickable
CNoSuchElementException because element is not found
DSyntaxError due to missing parentheses
Attempts:
2 left
💡 Hint
Check how locators are passed to expected conditions.
🧠 Conceptual
advanced
2:00remaining
Understanding expected condition behavior
Which statement best describes the behavior of the expected condition 'presence_of_element_located' in Selenium?
AIt waits until the element is invisible or removed from the DOM
BIt waits until the element is present in the DOM, regardless of visibility
CIt waits until the element's text matches a given string
DIt waits until the element is visible and enabled for clicking
Attempts:
2 left
💡 Hint
Think about presence vs visibility.
❓ framework
expert
3:00remaining
Best practice for waiting for multiple conditions
You want to wait until either an element with id 'success-msg' is visible or an element with id 'error-msg' is visible, whichever appears first. Which Selenium Python code snippet correctly implements this using expected conditions?
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, 20)

# Choose the correct code:
Await.until(EC.or_(EC.visibility_of_element_located((By.ID, 'success-msg')), EC.visibility_of_element_located((By.ID, 'error-msg'))))
Bwait.until(EC.visibility_of_element_located((By.ID, 'success-msg')) or EC.visibility_of_element_located((By.ID, 'error-msg')))
Cwait.until(EC.any_of(EC.visibility_of_element_located((By.ID, 'success-msg')), EC.visibility_of_element_located((By.ID, 'error-msg'))))
Dwait.until(EC.visibility_of_element_located((By.ID, 'success-msg')) and EC.visibility_of_element_located((By.ID, 'error-msg')))
Attempts:
2 left
💡 Hint
Look for the expected condition that waits for any one of multiple conditions.

Practice

(1/5)
1. What is the main purpose of using ExpectedConditions in Selenium WebDriver?
easy
A. To wait for certain conditions before interacting with elements
B. To speed up the test execution by skipping waits
C. To generate random test data automatically
D. To take screenshots during test execution

Solution

  1. Step 1: Understand ExpectedConditions role

    ExpectedConditions help Selenium wait for specific states like element visibility or clickability before proceeding.
  2. Step 2: Identify the main purpose

    This waiting avoids errors caused by trying to interact with elements not yet ready on the page.
  3. Final Answer:

    To wait for certain conditions before interacting with elements -> Option A
  4. Quick Check:

    ExpectedConditions = Wait for conditions [OK]
Hint: ExpectedConditions = smart waits before actions [OK]
Common Mistakes:
  • Thinking ExpectedConditions speed up tests by skipping waits
  • Confusing ExpectedConditions with data generation
  • Assuming ExpectedConditions take screenshots
2. Which of the following is the correct syntax to wait until an element located by ID 'submit' is clickable using Selenium's ExpectedConditions in Python?
easy
A. WebDriverWait(driver, 10).until(EC.visibility_of_element_located('submit'))
B. WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'submit')))
C. WebDriverWait(driver, 10).until(EC.element_to_be_clickable('submit'))
D. WebDriverWait(driver, 10).until(EC.presence_of_element_located(By.ID, 'submit'))

Solution

  1. Step 1: Check correct ExpectedCondition usage

    element_to_be_clickable requires a locator tuple like (By.ID, 'submit').
  2. Step 2: Verify syntax correctness

    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'submit'))) correctly uses a tuple inside the condition and waits properly.
  3. Final Answer:

    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'submit'))) -> Option B
  4. Quick Check:

    Use tuple locator with element_to_be_clickable [OK]
Hint: Use (By.ID, 'id') tuple inside ExpectedConditions [OK]
Common Mistakes:
  • Passing string instead of locator tuple
  • Using visibility_of_element_located instead of clickable
  • Missing parentheses around locator tuple
3. What will be the output of the following code snippet if the element with ID 'login' becomes visible after 5 seconds?
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)
element = wait.until(EC.visibility_of_element_located((By.ID, 'login')))
print(element.is_displayed())
medium
A. TimeoutException
B. False
C. True
D. NoSuchElementException

Solution

  1. Step 1: Analyze wait duration and element visibility

    The wait is 10 seconds, and the element appears after 5 seconds, so wait.until succeeds.
  2. Step 2: Understand is_displayed() output

    Since the element is visible, element.is_displayed() returns True, which is printed.
  3. Final Answer:

    True -> Option C
  4. Quick Check:

    Element visible within wait = True output [OK]
Hint: If element appears before timeout, is_displayed() is True [OK]
Common Mistakes:
  • Expecting TimeoutException though element appears in time
  • Confusing is_displayed() with presence only
  • Assuming False if element appears late but within wait
4. Identify the error in the following code that waits for an element with class name 'btn' to be clickable:
wait = WebDriverWait(driver, 5)
wait.until(EC.element_to_be_clickable(By.CLASS_NAME, 'btn'))
medium
A. Timeout value too low
B. Incorrect import of WebDriverWait
C. Using CLASS_NAME instead of CSS_SELECTOR
D. Missing tuple around locator in element_to_be_clickable

Solution

  1. Step 1: Check element_to_be_clickable parameter

    It requires a single locator tuple like (By.CLASS_NAME, 'btn'), not two separate arguments.
  2. Step 2: Identify syntax error

    Code passes two arguments instead of one tuple, causing a TypeError.
  3. Final Answer:

    Missing tuple around locator in element_to_be_clickable -> Option D
  4. Quick Check:

    Locator must be a tuple inside ExpectedConditions [OK]
Hint: Always wrap locator in a tuple for ExpectedConditions [OK]
Common Mistakes:
  • Passing locator arguments separately instead of tuple
  • Assuming timeout value causes error here
  • Confusing locator types (CLASS_NAME vs CSS_SELECTOR)
5. You want to wait until the URL contains the word 'dashboard' before proceeding. Which code snippet correctly uses ExpectedConditions to achieve this in Python Selenium?
hard
A. WebDriverWait(driver, 15).until(EC.url_contains('dashboard'))
B. WebDriverWait(driver, 15).until(EC.url_to_be('dashboard'))
C. WebDriverWait(driver, 15).until(EC.url_matches('dashboard'))
D. WebDriverWait(driver, 15).until(EC.url_is('dashboard'))

Solution

  1. Step 1: Identify correct ExpectedCondition for URL substring

    EC.url_contains waits until the URL contains the given substring.
  2. Step 2: Verify other options

    url_matches requires a regex pattern to match the entire URL, url_to_be checks for exact URL equality, and url_is is not a valid ExpectedCondition.
  3. Final Answer:

    WebDriverWait(driver, 15).until(EC.url_contains('dashboard')) -> Option A
  4. Quick Check:

    Use url_contains for substring in URL [OK]
Hint: Use EC.url_contains for partial URL waits [OK]
Common Mistakes:
  • Using non-existent ExpectedConditions like url_is
  • Confusing url_contains with exact match conditions like url_to_be
  • Using url_matches without proper regex for substring
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard