0
0
Selenium Javatesting~20 mins

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

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PartialLinkText Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Selenium Java code snippet?

Consider the following Selenium Java code that tries to find a link by partial link text and click it. What will be the output if the page contains a link with text "Learn Selenium Testing"?

Selenium Java
WebDriver driver = new ChromeDriver();
driver.get("http://example.com");
WebElement link = driver.findElement(By.partialLinkText("Selenium"));
link.click();
System.out.println("Clicked link with partial text 'Selenium'");
ANoSuchElementException at findElement
BStaleElementReferenceException at click
CTimeoutException waiting for page load
DClicked link with partial text 'Selenium'
Attempts:
2 left
💡 Hint

Partial link text matches any part of the link's visible text.

assertion
intermediate
2:00remaining
Which assertion correctly verifies the link text found by partialLinkText?

You have located a link using driver.findElement(By.partialLinkText("Start")). The full link text is "Start Your Free Trial". Which assertion correctly verifies the link text?

Selenium Java
WebElement link = driver.findElement(By.partialLinkText("Start"));
AassertEquals("Start Your Free Trial", link.getText());
BassertFalse(link.getText().startsWith("Free"));
CassertTrue(link.getText().contains("Start"));
DassertNull(link.getText());
Attempts:
2 left
💡 Hint

Partial link text locator finds links containing the substring, so the text should contain "Start".

🔧 Debug
advanced
2:00remaining
Why does this Selenium code throw NoSuchElementException?

The following code throws NoSuchElementException. The page has a link with text "Contact Us Today". What is the most likely reason?

Selenium Java
WebElement link = driver.findElement(By.partialLinkText("contact us"));
link.click();
AThe link is inside an iframe and not switched to it
BPartial link text is case sensitive, so "contact us" does not match "Contact Us Today"
CThe link is disabled and cannot be found
DThe page has not loaded yet, causing the element to be missing
Attempts:
2 left
💡 Hint

Check if the element is inside an iframe or frame.

framework
advanced
2:00remaining
Which TestNG annotation is best to initialize WebDriver before tests using partialLinkText?

You want to initialize the WebDriver once before all tests that use findElement(By.partialLinkText()). Which TestNG annotation should you use?

A@BeforeClass
B@BeforeMethod
C@BeforeTest
D@BeforeSuite
Attempts:
2 left
💡 Hint

Consider initializing WebDriver once per test class.

🧠 Conceptual
expert
2:00remaining
What is a limitation of using findElement(By.partialLinkText()) in Selenium?

Which of the following is a known limitation when using findElement(By.partialLinkText())?

AIt only works with exact full link text matches
BIt can match multiple links, but returns only the first match, which may cause ambiguity
CIt requires the link text to be an exact case-sensitive match
DIt cannot find links inside shadow DOM elements
Attempts:
2 left
💡 Hint

Think about how partial matching works and what happens if multiple links contain the substring.