0
0
Selenium Pythontesting~20 mins

Typing text (send_keys) in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Typing Text Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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)
A"TestUse1"
B"TestUser\b1"
C"TestUser"
D"TestUser1"
Attempts:
2 left
💡 Hint
Think about what the BACKSPACE key does when sent to the input field.
assertion
intermediate
1: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")
Aassert actual_text == "user@example.com"
Bassert actual_text.contains("user@example.com")
Cassert input_element.text == "user@example.com"
Dassert input_element.get_text() == "user@example.com"
Attempts:
2 left
💡 Hint
Remember how to get the value typed inside an input field.
locator
advanced
2: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:
Adriver.find_element(By.ID, "userEmail")
Bdriver.find_element(By.CSS_SELECTOR, "input[type='email']")
Cdriver.find_element(By.NAME, "userEmail")
Ddriver.find_element(By.XPATH, "//input[@placeholder='Enter your email']")
Attempts:
2 left
💡 Hint
Check which attribute uniquely identifies the input field.
🔧 Debug
advanced
2: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?
AThe driver session is closed before send_keys runs.
BThe input field is disabled or readonly, so send_keys has no effect.
Csend_keys requires clicking the input first to focus it.
DThe locator By.ID, "search" is incorrect and finds no element.
Attempts:
2 left
💡 Hint
Check if the input allows typing or is blocked.
framework
expert
3: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)
A
input_element = wait.until(EC.staleness_of(driver.find_element(By.ID, "input1")))
input_element.send_keys("hello")
B
input_element = wait.until(EC.presence_of_element_located((By.ID, "input1")))
input_element.send_keys("hello")
C
input_element = wait.until(EC.visibility_of_element_located((By.ID, "input1")))
input_element.send_keys("hello")
D
input_element = wait.until(EC.element_to_be_clickable((By.ID, "input1")))
input_element.send_keys("hello")
Attempts:
2 left
💡 Hint
Typing requires the element to be visible and enabled (clickable).