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"?
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'");
Partial link text matches any part of the link's visible text.
The findElement(By.partialLinkText("Selenium")) finds the link containing "Selenium" in its text. Since the link "Learn Selenium Testing" exists, it will be found and clicked successfully, printing the message.
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?
WebElement link = driver.findElement(By.partialLinkText("Start"));Partial link text locator finds links containing the substring, so the text should contain "Start".
Since the link text is "Start Your Free Trial", it contains "Start". The assertion assertTrue(link.getText().contains("Start")) correctly verifies this. Option C is also correct logically but the question asks for verification related to partial link text, so D is the best fit. Options B and C are incorrect.
The following code throws NoSuchElementException. The page has a link with text "Contact Us Today". What is the most likely reason?
WebElement link = driver.findElement(By.partialLinkText("contact us"));
link.click();Check if the element is inside an iframe or frame.
Partial link text matching is case insensitive in Selenium, so option A is incorrect. If the element is inside an iframe and the driver has not switched to it, Selenium cannot find it, causing NoSuchElementException. This is the most common cause here. Disabled links are still found by Selenium, so C is incorrect. Page load timing issues cause different exceptions or require waits, so D is less likely.
You want to initialize the WebDriver once before all tests that use findElement(By.partialLinkText()). Which TestNG annotation should you use?
Consider initializing WebDriver once per test class.
@BeforeClass runs once before any test methods in the current class, ideal for initializing WebDriver once per class. @BeforeMethod runs before each test method, causing repeated initialization. @BeforeTest runs before a group of classes defined in testng.xml, which may be broader than needed. @BeforeSuite runs once before all tests in the suite, which may be too early or broad.
Which of the following is a known limitation when using findElement(By.partialLinkText())?
Think about how partial matching works and what happens if multiple links contain the substring.
Partial link text matches any link containing the substring, so if multiple links contain it, Selenium returns the first one found. This can cause ambiguity if the test expects a specific link. Option B is false because partialLinkText matches substrings, not exact full text. Option B is false because matching is case insensitive. Option B is true but applies to all standard locators, not specific to partialLinkText, so C is the best answer.