Bird
Raised Fist0
Selenium Pythontesting~20 mins

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

Choose your learning style10 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).

Practice

(1/5)
1. What does the send_keys method do in Selenium Python?
easy
A. It types text into input fields or other elements.
B. It clicks on buttons or links.
C. It retrieves the text from an element.
D. It waits for an element to be visible.

Solution

  1. Step 1: Understand the purpose of send_keys

    The send_keys method simulates typing text into input fields or editable elements in Selenium.
  2. Step 2: Differentiate from other actions

    Clicking, retrieving text, or waiting are done by other methods like click(), text property, or WebDriverWait.
  3. Final Answer:

    It types text into input fields or other elements. -> Option A
  4. Quick Check:

    send_keys = types text [OK]
Hint: send_keys means typing text into fields [OK]
Common Mistakes:
  • Confusing send_keys with click()
  • Thinking send_keys reads text
  • Assuming send_keys waits for elements
2. Which of the following is the correct syntax to type the text "hello" into an input element stored in variable input_box?
easy
A. input_box.write("hello")
B. input_box.send_keys("hello")
C. input_box.enter("hello")
D. input_box.type("hello")

Solution

  1. Step 1: Recall the method name for typing text

    In Selenium Python, the method to type text is send_keys().
  2. Step 2: Check the syntax correctness

    The correct syntax is calling send_keys on the element with the text as a string argument.
  3. Final Answer:

    input_box.send_keys("hello") -> Option B
  4. Quick Check:

    Correct method is send_keys() [OK]
Hint: Use send_keys() to type text, not type() or enter() [OK]
Common Mistakes:
  • Using non-existent methods like type() or enter()
  • Forgetting parentheses after send_keys
  • Passing non-string arguments
3. What will be the value of the input box after executing this code?
input_box = driver.find_element(By.ID, "username")
input_box.send_keys("user123")
print(input_box.get_attribute("value"))
medium
A. "" (empty string)
B. "input_box"
C. "user123"
D. Throws an error

Solution

  1. Step 1: Understand send_keys effect on input value

    Calling send_keys("user123") types "user123" into the input box, setting its value attribute.
  2. Step 2: Retrieve the value attribute

    get_attribute("value") returns the current text inside the input box, which is "user123".
  3. Final Answer:

    "user123" -> Option C
  4. Quick Check:

    send_keys sets value attribute = "user123" [OK]
Hint: send_keys sets input value; get_attribute('value') reads it [OK]
Common Mistakes:
  • Expecting get_attribute to return element name
  • Thinking send_keys clears input automatically
  • Assuming print shows element object
4. You want to type "admin" into an input box but your test fails with an error. Which line fixes the error?
input_box = driver.find_element(By.ID, "user")
input_box.send_keys(admin)
medium
A. input_box.send_keys("admin")
B. input_box.send_keys('admin")
C. input_box.send_keys(admin)
D. input_box.send_keys()

Solution

  1. Step 1: Identify the error cause

    The argument admin is not in quotes, so Python treats it as a variable, causing a NameError.
  2. Step 2: Fix by passing a string literal

    Enclose "admin" in quotes to pass it as a string: send_keys("admin").
  3. Final Answer:

    input_box.send_keys("admin") -> Option A
  4. Quick Check:

    Text must be a string in quotes [OK]
Hint: Always put text in quotes inside send_keys() [OK]
Common Mistakes:
  • Passing variable without quotes
  • Leaving send_keys empty
  • Using single quotes inconsistently (valid but watch syntax)
5. You want to type a password into a field but first clear any existing text. Which code snippet correctly does this?
hard
A. input_box.clear("mypassword")
B. input_box.send_keys("") input_box.send_keys("mypassword")
C. input_box.send_keys("mypassword") input_box.clear()
D. input_box.clear() input_box.send_keys("mypassword")

Solution

  1. Step 1: Clear existing text before typing

    Use clear() method to remove any existing text in the input box.
  2. Step 2: Type the new password

    After clearing, call send_keys("mypassword") to type the password.
  3. Final Answer:

    input_box.clear() input_box.send_keys("mypassword") -> Option D
  4. Quick Check:

    Clear first, then send_keys [OK]
Hint: Clear input before typing new text with clear() [OK]
Common Mistakes:
  • Typing before clearing causes leftover text
  • Using clear() with arguments (invalid)
  • Sending empty string to clear input
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