Challenge - 5 Problems
LinkText Locator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Selenium Java code snippet?
Consider the following Selenium Java code that tries to find a link by its exact visible text and clicks it. What will happen when this code runs if the link with text "Home" exists on the page?
Selenium Java
WebDriver driver = new ChromeDriver(); driver.get("https://example.com"); WebElement link = driver.findElement(By.linkText("Home")); link.click(); System.out.println("Clicked the Home link");
Attempts:
2 left
💡 Hint
Remember that findElement(By.linkText()) matches the exact visible text of the link.
✗ Incorrect
The findElement(By.linkText("Home")) locates the anchor element whose visible text exactly matches "Home". If found, clicking it navigates the browser and the print statement executes. The method is case-sensitive and requires exact match.
❓ assertion
intermediate2:00remaining
Which assertion correctly verifies the link text found by findElement(By.linkText())?
You have located a link using findElement(By.linkText("Contact Us")). Which assertion correctly checks that the link's visible text is exactly "Contact Us"?
Selenium Java
WebElement contactLink = driver.findElement(By.linkText("Contact Us"));Attempts:
2 left
💡 Hint
Check for exact text equality, not partial or case-insensitive matches.
✗ Incorrect
assertEquals("Contact Us", contactLink.getText()) verifies the link's visible text exactly matches "Contact Us". Other options check partial text, attribute presence, or negate case-insensitive equality, which are not exact text assertions.
🔧 Debug
advanced2:00remaining
Why does this findElement(By.linkText()) call throw NoSuchElementException?
Given the code below, why does the findElement call throw NoSuchElementException even though the link text "About Us" is visible on the page?
Selenium Java
WebElement aboutLink = driver.findElement(By.linkText("About Us"));Attempts:
2 left
💡 Hint
Check if the element is inside a frame or iframe that requires switching context.
✗ Incorrect
If the link is inside an iframe, Selenium cannot find it unless the driver switches to that iframe first. The NoSuchElementException occurs because the element is not in the current DOM context. linkText is case-sensitive and requires exact match, but that is not the cause here.
🧠 Conceptual
advanced2:00remaining
What is a limitation of using findElement(By.linkText()) in Selenium tests?
Which of the following is a known limitation when using findElement(By.linkText()) to locate links in Selenium?
Attempts:
2 left
💡 Hint
Think about how exact the text match must be for linkText locator.
✗ Incorrect
findElement(By.linkText()) requires the link's visible text to match exactly, including case and spacing. It does not support partial matches (use By.partialLinkText for that). It does not handle shadow DOM automatically nor does it implicitly wait for 30 seconds.
❓ framework
expert3:00remaining
How to implement a robust method to click a link by visible text using Selenium Java?
You want to create a reusable method in your Selenium Java test framework that clicks a link by its visible text. The method should handle the case where the link is inside an iframe and wait up to 10 seconds for the link to be clickable. Which code snippet correctly implements this?
Attempts:
2 left
💡 Hint
Consider iframe switching, explicit wait, and exact link text matching.
✗ Incorrect
Option A switches to the iframe named "frame1", waits up to 10 seconds for the link with exact visible text to be clickable, clicks it, then switches back to the main page. This handles iframe context and waiting properly. Other options miss iframe switching, waiting, or use partialLinkText which is not exact.