Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using sendKeys instead of clear to remove text
Using click which only focuses the field
✗ Incorrect
The clear() method removes any text from the input field.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.id when the element has no id
Using By.className which looks for CSS classes
✗ Incorrect
The By.name locator finds elements by their name attribute.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using sendKeys instead of clear
Using getText which only reads text
✗ Incorrect
The clear() method is used to empty the text in input fields.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.id with a CSS selector string
Using click instead of clear to empty the field
✗ Incorrect
Use By.cssSelector to find the element by CSS selector, then clear() to empty it.
5fill in blank
hardFill 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'
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
✗ Incorrect
Find the element by XPath, clear existing text, then send new text using sendKeys().