Skip to content
CodeKruPro

Match a link by part of its text

Automation taskEasyAsked in: Accenture, Capgemini, Infosys, TCS, Wipro

A common follow-up: "The link text has a changing count, like Inbox (12). How do you find it?" Partial link text matches a fixed part of the text, such as Inbox, and ignores the rest. Here you find two links by a fixed part of their text and print each full link text.

Find Element by Partial Link Text

Video walkthrough

Watch on YouTube

Find Element by Partial Link Text

The By.partialLinkText() locator finds a link using part of its visible text. This is useful when link text is long or dynamic.

On the Links page, there are three "Practice" links:

  • Practice TextFields
  • Practice Buttons
  • Practice Checkboxes

Task:

  1. Navigate to https://testkru.com/Elements/Links
  2. Find the link containing text TextFields
  3. Print its full text
  4. Find the link containing text Buttons
  5. Print its full text

Expected output:

Link 1: Practice TextFields
Link 2: Practice Buttons