0
0
Selenium Javatesting~20 mins

findElement by tagName in Selenium Java - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
TagName Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of findElement by tagName usage
What will be the output of the following Selenium Java code snippet when executed on a webpage with multiple
Selenium Java
WebElement button = driver.findElement(By.tagName("button"));
System.out.println(button.getText());
ASubmit
BNoSuchElementException
CAll button texts concatenated
Dnull
Attempts:
2 left
💡 Hint
findElement returns the first matching element found in the DOM.
assertion
intermediate
2:00remaining
Correct assertion for findElement by tagName
Which assertion correctly verifies that the first

element on the page contains the text 'Welcome'?

Selenium Java
WebElement header = driver.findElement(By.tagName("h1"));
AassertFalse(header.getText().isEmpty());
BassertTrue(header.getText().contains("Welcome"));
CassertEquals("Welcome", header.getText());
DassertNotNull(header.getText());
Attempts:
2 left
💡 Hint
Use exact text match for verification.
locator
advanced
2:00remaining
Best locator for unique
element
You want to locate the unique
element on a webpage using Selenium Java. Which locator is the best choice?
ABy.tagName("footer")
BBy.id("footer")
CBy.className("footer")
DBy.xpath("//footer")
Attempts:
2 left
💡 Hint
Unique IDs are the most reliable locators.
🔧 Debug
advanced
2:00remaining
Debugging NoSuchElementException with findElement by tagName
Given the code snippet below, what is the most likely cause of a NoSuchElementException?
Selenium Java
WebElement input = driver.findElement(By.tagName("input"));
input.sendKeys("test");
AThe input element is inside an iframe not switched to.
BNo <input> element is present in the current page DOM.
CThe input element is present but disabled.
DThe input element has no 'name' attribute.
Attempts:
2 left
💡 Hint
Check if the element is inside frames or iframes.
framework
expert
2:00remaining
TestNG test method using findElement by tagName
Which TestNG test method correctly finds the first

element and asserts its text equals 'Hello World'?

A
@Test
public void testParagraphText() {
  WebElement para = driver.findElement(By.tagName("p"));
  Assert.assertFalse(para.getText().isEmpty());
}
B
@Test
public void testParagraphText() {
  WebElement para = driver.findElement(By.tagName("p"));
  Assert.assertTrue(para.getText().equalsIgnoreCase("Hello World"));
}
C
@Test
public void testParagraphText() {
  WebElement para = driver.findElement(By.tagName("p"));
  Assert.assertNotNull(para.getText());
}
D
@Test
public void testParagraphText() {
  WebElement para = driver.findElement(By.tagName("p"));
  Assert.assertEquals(para.getText(), "Hello World");
}
Attempts:
2 left
💡 Hint
Use assertEquals for exact text match in TestNG.