Challenge - 5 Problems
TagName Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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());Attempts:
2 left
💡 Hint
findElement returns the first matching element found in the DOM.
✗ Incorrect
The findElement method with By.tagName("button") returns the first
❓ assertion
intermediate2: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"));Attempts:
2 left
💡 Hint
Use exact text match for verification.
✗ Incorrect
assertEquals("Welcome", header.getText()) checks that the header text exactly matches 'Welcome', which is the correct way to verify the text content.
❓ locator
advanced2:00remaining
Best locator for unique
You want to locate the unique
Attempts:
2 left
💡 Hint
Unique IDs are the most reliable locators.
✗ Incorrect
Using By.id("footer") is best if the footer element has a unique id attribute. It is faster and more reliable than tagName or xpath.
🔧 Debug
advanced2: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");
Attempts:
2 left
💡 Hint
Check if the element is inside frames or iframes.
✗ Incorrect
If the input element is inside an iframe, Selenium cannot find it until driver switches to that iframe. This causes NoSuchElementException.
❓ framework
expert2:00remaining
TestNG test method using findElement by tagName
Which TestNG test method correctly finds the first
element and asserts its text equals 'Hello World'?
Attempts:
2 left
💡 Hint
Use assertEquals for exact text match in TestNG.
✗ Incorrect
Option D uses Assert.assertEquals to check the paragraph text exactly matches 'Hello World', which is the correct assertion for this test.