Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to find an element by its name attribute.
Selenium Java
WebElement element = driver.findElement(By.[1]("username"));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.id instead of By.name
Using By.className which looks for class attribute
✗ Incorrect
The By.name locator finds elements by their name attribute.
2fill in blank
mediumComplete the code to click on the element found by name.
Selenium Java
driver.findElement(By.[1]("submitBtn")).click();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.id or other locators instead of By.name
Forgetting to call click() after finding the element
✗ Incorrect
Clicking the element found by By.name requires using By.name locator.
3fill in blank
hardFix the error in the code to correctly find element by name.
Selenium Java
WebElement input = driver.findElement(By.[1]("email"));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.id or By.className which do not match the name attribute
Using By.linkText which is for links only
✗ Incorrect
The correct locator to find by the name attribute is By.name.
4fill in blank
hardFill both blanks to create a test that finds an element by name and sends keys.
Selenium Java
WebElement input = driver.findElement(By.[1]("search")); input.[2]("Selenium");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using click() instead of sendKeys() to enter text
Using By.id instead of By.name
✗ Incorrect
Use By.name to find the element by name, then sendKeys to type text.
5fill in blank
hardFill all three blanks to find an element by name, clear it, and enter new text.
Selenium Java
WebElement input = driver.findElement(By.[1]("username")); input.[2](); input.[3]("newuser");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to clear the input before sending keys
Using click() instead of clear() or sendKeys()
✗ Incorrect
Find element by By.name, clear existing text with clear(), then enter new text with sendKeys().