Home > Automation Testing > Selenium Locator: Link Text and Partial Link Text

Selenium Locator: Link Text and Partial Link Text

This post was most recently updated on June 14th, 2019

Locator Type:  Link Text or Partial Link Text.

  • This locator is used to locate anchor web element using it’s text.
  • Link text is a element text between opening <a> and closing anchor tag </a>.
  • Partial link text is used to find anchor element similar to point 1 but it used partial unique text to locate element. It is useful to get rid of large link text.

Java code to find web element

Using link text

WebElement linkTextElement=driver.findElement(By.linkText("Link_text")); 

Using partial link text

WebElement plinkTextElement=driver.findElement(By.partialLinkText("Partial_Link_Text")); 

Example →

To locate element using link text:

    • Go to https://www.societyhive.com/
    • Inspect menu option FEATURE
    • Use link text to find web element.

WebElement linkText=driver.findElement(By.linkText("FEATURES"));

To locate element using partial link text:

    • Go to https://www.societyhive.com/
    • Inspect for link contains text “cooperative housing societies”
    • Use partial link text to find web element.

WebElement partialLinkText=driver.findElement(By.partialLinkText("cooperative housing societies")); 


Perform click on Link(find by link text and partial link text):

Selenium Tutorial >>

This Article is TAGGED in , , . BOOKMARK THE permalink.

Avatar photo
Neeraj Vishwakarma
Senior QA Engineer Skills: Automation Testing, Manual Testing, STLC, Java, Selenium Webdriver, Protractor, Database Testing.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">