0
0
Selenium Pythontesting~20 mins

Checking element state (displayed, enabled, selected) in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Element State Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Check if a button is enabled using Selenium
What will be the output of this code snippet when the button is enabled on the page?
Selenium Python
from selenium import webdriver
from selenium.webdriver.common.by import By

# Assume driver is already initialized and page loaded
button = driver.find_element(By.ID, 'submit-btn')
print(button.is_enabled())
ARaises NoSuchElementException
BTrue
CNone
DFalse
Attempts:
2 left
💡 Hint
The is_enabled() method returns True if the element is enabled and can be interacted with.
assertion
intermediate
2:00remaining
Assert that a checkbox is selected
Which assertion correctly verifies that a checkbox with id 'agree' is selected?
Selenium Python
checkbox = driver.find_element(By.ID, 'agree')
Aassert checkbox.is_enabled() == False
Bassert checkbox.is_displayed() == True
Cassert checkbox.get_attribute('checked') == 'false'
Dassert checkbox.is_selected() == True
Attempts:
2 left
💡 Hint
Use the method that checks if the element is selected.
🔧 Debug
advanced
2:00remaining
Identify the error in checking if an element is displayed
What error will this code raise when the element with id 'hidden-div' is not present on the page?
Selenium Python
element = driver.find_element(By.ID, 'hidden-div')
print(element.is_displayed())
ANoSuchElementException
BAttributeError
CTimeoutException
DStaleElementReferenceException
Attempts:
2 left
💡 Hint
Check what happens when find_element cannot find the element.
🧠 Conceptual
advanced
2:00remaining
Understanding difference between is_displayed() and is_enabled()
Which statement correctly describes the difference between is_displayed() and is_enabled() methods in Selenium?
Ais_displayed() checks if element is visible; is_enabled() checks if element can be interacted with
Bis_displayed() checks if element is enabled; is_enabled() checks if element is visible
CBoth methods check if element is visible on the page
DBoth methods check if element is enabled for interaction
Attempts:
2 left
💡 Hint
Think about visibility versus interactivity.
framework
expert
3:00remaining
Best practice for waiting until a checkbox is selected
Which Selenium WebDriverWait usage correctly waits until a checkbox with id 'subscribe' is selected?
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)
Await.until(EC.visibility_of_element_located((By.ID, 'subscribe')))
Bwait.until(EC.element_to_be_clickable((By.ID, 'subscribe')))
Cwait.until(EC.element_to_be_selected((By.ID, 'subscribe')))
Dwait.until(EC.presence_of_element_located((By.ID, 'subscribe')))
Attempts:
2 left
💡 Hint
Use the expected condition that waits for selection state.