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?✗ Incorrect
sendKeys() types text or keys into an input or element.Which locator is commonly used before
sendKeys()?✗ Incorrect
You locate the element first, often by
By.id, before typing.How do you send the ENTER key using
sendKeys()?✗ Incorrect
Special keys use the
Keys enum, like Keys.ENTER.What happens if you call
sendKeys() without clearing the input first?✗ Incorrect
sendKeys() appends text; clearing is needed to avoid extra text.Which of these is a valid way to clear an input before typing?
✗ Incorrect
clear() empties the input field before typing.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.