0
0
Selenium Javatesting~10 mins

Clearing fields 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 clear the input field using Selenium WebDriver.

Selenium Java
WebElement inputField = driver.findElement(By.id("username"));
inputField.[1]();
Drag options to blanks, or click blank then click option'
AsendKeys
Bclick
Cclear
Dsubmit
Attempts:
3 left
💡 Hint
Common Mistakes
Using sendKeys instead of clear to remove text
Using click which only focuses the field
2fill in blank
medium

Complete the code to find the input field by its name attribute and clear it.

Selenium Java
WebElement searchBox = driver.findElement(By.[1]("q"));
searchBox.clear();
Drag options to blanks, or click blank then click option'
Aname
Bid
CclassName
DtagName
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.id when the element has no id
Using By.className which looks for CSS classes
3fill in blank
hard

Fix the error in the code to clear the password field.

Selenium Java
WebElement passwordInput = driver.findElement(By.id("password"));
passwordInput.[1]();
Drag options to blanks, or click blank then click option'
AsendKeys
Bclick
CgetText
Dclear
Attempts:
3 left
💡 Hint
Common Mistakes
Using sendKeys instead of clear
Using getText which only reads text
4fill in blank
hard

Fill both blanks to clear the email input field found by CSS selector.

Selenium Java
WebElement emailField = driver.findElement(By.[1]("input[type='email']"));
emailField.[2]();
Drag options to blanks, or click blank then click option'
AcssSelector
Bclear
Cclick
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.id with a CSS selector string
Using click instead of clear to empty the field
5fill in blank
hard

Fill all three blanks to find the textarea by XPath, clear it, and then send new text.

Selenium Java
WebElement commentBox = driver.findElement(By.[1]("//textarea[@name='comment']"));
commentBox.[2]();
commentBox.[3]("Great post!");
Drag options to blanks, or click blank then click option'
Axpath
Bclear
CsendKeys
DcssSelector
Attempts:
3 left
💡 Hint
Common Mistakes
Using cssSelector instead of xpath for the locator
Forgetting to clear before sending keys
Using click instead of clear