0
0
Selenium Javatesting~20 mins

Typing text (sendKeys) in Selenium Java - 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 result of this Selenium Java code snippet?
Consider the following Selenium Java code that types text into a search box and submits the form. What will be the value of the input field after execution?
Selenium Java
WebElement searchBox = driver.findElement(By.id("searchInput"));
searchBox.sendKeys("Selenium Testing");
String enteredText = searchBox.getAttribute("value");
A""
B"selenium testing"
C"Selenium Testing"
Dnull
Attempts:
2 left
💡 Hint
Remember that sendKeys types exactly what you pass as argument.
assertion
intermediate
2:00remaining
Which assertion correctly verifies typed text in Selenium Java?
You want to check that the text "Hello World" was typed into an input field with id "message". Which assertion is correct?
Selenium Java
WebElement input = driver.findElement(By.id("message"));
input.sendKeys("Hello World");
String text = input.getAttribute("value");
AassertTrue(text.contains("hello world"));
BassertEquals(text, "Hello World");
CassertNotNull(text);
DassertFalse(text.isEmpty());
Attempts:
2 left
💡 Hint
Check for exact match of the typed text.
locator
advanced
2:00remaining
Which locator is best to find an input field for typing text?
You want to type text into a username field on a login page. Which locator is the best practice for finding this input element?
ABy.tagName("input")
BBy.xpath("//input[@type='text']")
CBy.className("input-field")
DBy.id("username")
Attempts:
2 left
💡 Hint
Use the most specific and stable locator.
🔧 Debug
advanced
2:00remaining
Why does this sendKeys call fail to type text?
This Selenium Java code tries to type "Test" but the input remains empty. What is the likely cause?
Selenium Java
WebElement input = driver.findElement(By.id("email"));
input.sendKeys("");
AsendKeys was called with an empty string, so no text is typed.
BThe input element is not visible, so sendKeys fails silently.
CThe locator By.id("email") is incorrect and finds no element.
DsendKeys requires a click() before typing.
Attempts:
2 left
💡 Hint
Check the argument passed to sendKeys.
framework
expert
2:00remaining
In a Selenium Java test framework, how to best wait for an input field to be ready before typing?
You want to type text into an input field, but it may take time to appear. Which approach ensures reliable typing?
AUse WebDriverWait with ExpectedConditions.elementToBeClickable before sendKeys.
BUse Thread.sleep(5000) before sendKeys to wait fixed time.
CCall sendKeys immediately and catch exceptions if element not ready.
DUse driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS) once before tests.
Attempts:
2 left
💡 Hint
Explicit waits are better than fixed or implicit waits for element readiness.