0
0
Selenium Javatesting~10 mins

Typing text (sendKeys) in Selenium Java - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to type text into the input field.

Selenium Java
WebElement input = driver.findElement(By.id("username"));
input.[1]("testuser");
Drag options to blanks, or click blank then click option'
AsendKeys
BgetText
Cclick
Dclear
Attempts:
3 left
💡 Hint
Common Mistakes
Using click instead of sendKeys
Using getText which only retrieves text
Using clear which removes text instead of typing
2fill in blank
medium

Complete the code to find the password input and type the password.

Selenium Java
WebElement passwordInput = driver.findElement(By.name("[1]"));
passwordInput.sendKeys("mypassword");
Drag options to blanks, or click blank then click option'
Aemail
Buser
Cpassword
Dsubmit
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'user' or 'email' which are for other fields
Using 'submit' which is usually a button
3fill in blank
hard

Fix the error in the code to type text into the search box.

Selenium Java
WebElement searchBox = driver.findElement(By.cssSelector("input.search"));
searchBox.[1]("Selenium testing");
Drag options to blanks, or click blank then click option'
AtypeKeys
Bsendkey
CinputText
DsendKeys
Attempts:
3 left
💡 Hint
Common Mistakes
Using sendkey without capital K
Using made-up methods like typeKeys or inputText
4fill in blank
hard

Fill both blanks to clear the input field and then type new text.

Selenium Java
WebElement inputField = driver.findElement(By.id("searchBox"));
inputField.[1]();
inputField.[2]("new query");
Drag options to blanks, or click blank then click option'
Aclear
BsendKeys
Cclick
DgetText
Attempts:
3 left
💡 Hint
Common Mistakes
Typing without clearing old text
Using click or getText instead of clear or sendKeys
5fill in blank
hard

Fill all three blanks to find the input by XPath, clear it, and type the text.

Selenium Java
WebElement input = driver.findElement(By.xpath("[1]"));
input.[2]();
input.[3]("hello world");
Drag options to blanks, or click blank then click option'
A//input[@type='text']
Bclear
CsendKeys
D//input[@name='search']
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong XPath expression
Forgetting to clear before typing
Using incorrect method names