Recall & Review
beginner
What does
findElement(By.partialLinkText()) do in Selenium?It finds the first web element on the page that contains the specified partial text inside a link (<a> tag). This helps locate links when you only know part of the link text.
Click to reveal answer
beginner
How is
partialLinkText different from linkText in Selenium?linkText matches the full visible text of a link exactly, while partialLinkText matches any part of the link's visible text. Use partialLinkText when you only know part of the link text.Click to reveal answer
beginner
Write a simple Java Selenium code snippet to click a link containing the text "Learn" using
partialLinkText.WebElement link = driver.findElement(By.partialLinkText("Learn"));
link.click();
Click to reveal answer
intermediate
Why might using
partialLinkText be risky in some tests?Because it matches any link containing the partial text, it might find multiple links or the wrong link if the partial text is too common. This can cause flaky or incorrect tests.
Click to reveal answer
intermediate
What is a good practice when using
partialLinkText locators?Use unique and specific partial text that clearly identifies the link you want. Avoid very short or common words to reduce the chance of matching multiple elements.
Click to reveal answer
What does
driver.findElement(By.partialLinkText("Home")) do?✗ Incorrect
partialLinkText finds the first link (<a>) containing the given partial text.Which locator would you use to find a link with exact text "Contact Us"?
✗ Incorrect
linkText matches the full visible text exactly.If multiple links contain the partial text, what does
findElement(By.partialLinkText()) return?✗ Incorrect
findElement returns the first matching element only.Why should you avoid very short partial texts like "a" in
partialLinkText?✗ Incorrect
Short partial texts are common and can match many links, making tests flaky.
Which HTML tag does
partialLinkText target?✗ Incorrect
partialLinkText locates <a> (link) elements.Explain how
findElement(By.partialLinkText()) works and when you would use it.Think about searching for a link when you only remember part of its text.
You got /4 concepts.
Describe best practices for choosing partial link text values in Selenium tests.
Consider how to make your locator reliable and stable.
You got /4 concepts.