Recall & Review
beginner
What does
findElement(By.linkText()) do in Selenium?It finds the first web element on the page that exactly matches the visible text of a link (anchor tag).
Click to reveal answer
beginner
How do you use
findElement(By.linkText()) to click a link with text "Home"?Use
driver.findElement(By.linkText("Home")).click(); to find and click the link with text "Home".Click to reveal answer
intermediate
What is the difference between
By.linkText() and By.partialLinkText()?By.linkText() matches the full visible text of a link exactly, while By.partialLinkText() matches any part of the link text.Click to reveal answer
intermediate
Why should you avoid using
findElement(By.linkText()) with very common link texts like "Click here"?Because it may find the wrong link if multiple links have the same text, causing flaky or incorrect tests.
Click to reveal answer
beginner
What exception is thrown if
findElement(By.linkText()) does not find any matching element?It throws
NoSuchElementException indicating no element with the given link text was found.Click to reveal answer
Which Selenium method finds a link by its exact visible text?
✗ Incorrect
By.linkText() matches the full visible text of a link exactly.
What happens if
findElement(By.linkText("Submit")) does not find a matching link?✗ Incorrect
Selenium throws NoSuchElementException when no element is found.
Which locator should you use to find a link containing the text "Login" anywhere in its visible text?
✗ Incorrect
By.partialLinkText() matches part of the link text.
Why is
By.linkText() considered a good locator for links?✗ Incorrect
Link text is user-visible and often stable, making it a reliable locator.
Which of these is a valid way to click a link with text "Contact Us" using Selenium Java?
✗ Incorrect
Use By.linkText() to find links by their visible text.
Explain how
findElement(By.linkText()) works and when to use it.Think about how you find a link on a webpage by reading its text.
You got /4 concepts.
Describe the difference between
By.linkText() and By.partialLinkText() in Selenium.Consider exact vs partial matching of link text.
You got /4 concepts.