Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to find an element by its tag name.
Selenium Java
WebElement element = driver.findElement(By.[1]("button"));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.id or By.className instead of By.tagName.
Forgetting to put the tag name string in quotes.
✗ Incorrect
The method findElement(By.tagName("button")) finds the first element with the tag
2fill in blank
mediumComplete the code to click the first <a> tag on the page.
Selenium Java
driver.findElement(By.[1]("a")).click();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.id or By.cssSelector when the question asks for tag name.
Trying to click without finding the element first.
✗ Incorrect
Using By.tagName("a") selects the first anchor tag on the page to click.
3fill in blank
hardFix the error in the code to find the first <input> element.
Selenium Java
WebElement input = driver.findElement(By.[1]("input"));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.name or By.className which look for attributes, not tags.
Using By.linkText which only works for links.
✗ Incorrect
To find elements by their tag, use By.tagName("input").
4fill in blank
hardFill both blanks to find the first <div> and get its text.
Selenium Java
String text = driver.findElement(By.[1]("div")).[2]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using click() instead of getText() to get text.
Using getAttribute() without specifying attribute name.
✗ Incorrect
Use By.tagName("div") to find the div, then getText() to get its text content.
5fill in blank
hardFill all three blanks to find the first <span>, check if displayed, and print its text.
Selenium Java
WebElement span = driver.findElement(By.[1]("span")); boolean visible = span.[2](); if (visible) { System.out.println(span.[3]()); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using click() instead of isDisplayed() to check visibility.
Trying to print element directly instead of its text.
✗ Incorrect
Find the element by tagName("span"), check visibility with isDisplayed(), then print text with getText().