Challenge - 5 Problems
Typing Text Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Selenium send_keys code?
Consider the following Selenium Python code snippet that types text into an input field. What will be the final value of the input field after execution?
Selenium Python
from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys input_element = driver.find_element(By.ID, "username") input_element.send_keys("TestUser") input_element.send_keys(Keys.BACKSPACE) input_element.send_keys("1") final_value = input_element.get_attribute("value") print(final_value)
Attempts:
2 left
💡 Hint
Think about what the BACKSPACE key does when sent to the input field.
✗ Incorrect
The send_keys method sends characters to the input field. Sending Keys.BACKSPACE deletes the last character 'r' from 'TestUser', resulting in 'TestUse'. Then sending '1' appends it, making the final value 'TestUse1'.
❓ assertion
intermediate1:30remaining
Which assertion correctly verifies typed text using send_keys?
You want to verify that the input field with id 'email' contains the text 'user@example.com' after typing. Which assertion is correct?
Selenium Python
input_element = driver.find_element(By.ID, "email") input_element.send_keys("user@example.com") actual_text = input_element.get_attribute("value")
Attempts:
2 left
💡 Hint
Remember how to get the value typed inside an input field.
✗ Incorrect
The correct way to get the typed text in an input field is to use get_attribute('value'). The 'text' property or get_text() do not return the input's typed value.
❓ locator
advanced2:00remaining
Which locator is best to find an input field for typing email?
You want to type an email into an input field. The HTML snippet is:
Attempts:
2 left
💡 Hint
Check which attribute uniquely identifies the input field.
✗ Incorrect
The input has no ID attribute, so By.ID won't work. The 'name' attribute is 'userEmail', which is unique and reliable. CSS selector by type may match multiple inputs. XPath by placeholder is less stable.
🔧 Debug
advanced2:30remaining
Why does send_keys fail to type text in this input?
Given this code:
input_element = driver.find_element(By.ID, "search")
input_element.send_keys("query")
But the input remains empty after running. What is the most likely reason?
Attempts:
2 left
💡 Hint
Check if the input allows typing or is blocked.
✗ Incorrect
If the input is disabled or readonly, send_keys will not change its value. The locator is found, and clicking is not required for send_keys to work. Driver session closed would cause an error.
❓ framework
expert3:00remaining
How to wait for input to be ready before send_keys in Selenium Python?
You want to type text into an input field that loads dynamically. Which code snippet correctly waits for the input to be visible and enabled before typing?
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)
Attempts:
2 left
💡 Hint
Typing requires the element to be visible and enabled (clickable).
✗ Incorrect
element_to_be_clickable waits for visibility and enabled state, ensuring send_keys works. presence_of_element_located only waits for presence in DOM, not visibility. visibility_of_element_located waits for visibility but not necessarily enabled. staleness_of waits for element to disappear.