0
0
Selenium Javatesting~5 mins

Typing text (sendKeys) in Selenium Java - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the sendKeys() method do in Selenium?
The sendKeys() method types text into an input field or element on a web page, simulating keyboard input.
Click to reveal answer
beginner
How do you locate a text input field before using sendKeys()?
You use a locator like By.id, By.name, or By.cssSelector to find the input element, then call sendKeys() on it.
Click to reveal answer
beginner
Example: Write a Java Selenium code snippet to type "hello" into an input with id "username".
WebElement input = driver.findElement(By.id("username")); input.sendKeys("hello");
Click to reveal answer
intermediate
Can sendKeys() be used to send special keys like ENTER or TAB?
Yes, by using the Keys enum, e.g., sendKeys(Keys.ENTER) to simulate pressing the Enter key.
Click to reveal answer
intermediate
Why is it important to clear an input field before using sendKeys()?
Because sendKeys() appends text. Clearing ensures the field is empty before typing new text to avoid unwanted input.
Click to reveal answer
What does sendKeys() do in Selenium?
ATypes text into a web element
BClicks a button
CFinds an element by ID
DWaits for a page to load
Which locator is commonly used before sendKeys()?
ABy.title
BBy.id
CBy.alert
DBy.cookie
How do you send the ENTER key using sendKeys()?
AsendKeys("\n")
BsendKeys("ENTER")
CsendKeys(Enter)
DsendKeys(Keys.ENTER)
What happens if you call sendKeys() without clearing the input first?
AIt appends the text
BIt deletes the element
CIt replaces the text
DIt throws an error
Which of these is a valid way to clear an input before typing?
Ainput.remove()
Binput.delete()
Cinput.clear()
Dinput.reset()
Explain how to use sendKeys() to type text into a web input field in Selenium Java.
Think about finding the element and then typing.
You got /3 concepts.
    Describe how to send special keys like ENTER using sendKeys().
    Special keys are not strings but constants.
    You got /3 concepts.