0
0
Selenium Javatesting~10 mins

findElement by tagName 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 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'
Aname
Bid
CclassName
DtagName
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.
2fill in blank
medium

Complete 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'
Aid
BtagName
CcssSelector
Dxpath
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.
3fill in blank
hard

Fix 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'
AtagName
Bname
CclassName
DlinkText
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.
4fill in blank
hard

Fill 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'
AtagName
BgetText
Cclick
DgetAttribute
Attempts:
3 left
💡 Hint
Common Mistakes
Using click() instead of getText() to get text.
Using getAttribute() without specifying attribute name.
5fill in blank
hard

Fill 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'
AtagName
BisDisplayed
CgetText
Dclick
Attempts:
3 left
💡 Hint
Common Mistakes
Using click() instead of isDisplayed() to check visibility.
Trying to print element directly instead of its text.