Continuous Test Orchestration And Execution Platform Online

Perform automatic and live-interactive testing on 3000+ existent desktop and mobile devices online.

Find Elements With Link Text & Partial Link Text In Selenium

Sadhvi Singh

Posted On: June 17, 2019

view count192270 Views

Read time6 Min Read

This article is a office of our Content Hub. For more than in-depth resources, check out our content hub on Selenium Locators Tutorial.

CSS locators in Selenium are a fundamental concept that every tester who aims to perform automation testing with Selenium, should be aware of. Proficient employ of CSS locators in Selenium can help you perform testing in a more efficient & thorough fashion. I accept been in the automation testing industry from 7 years now, & I often find that testers when performing Selenium, tend to forget the purpose of each CSS locator. Freshers have a tough fourth dimension understanding them & experienced tester oftentimes sticks to a couple of selectors for locating elements on a webpage as they execute automation testing with Selenium.

There accept been times where I meet an experienced automation tester taking a longer route for finding an chemical element equally they have a addiction of sticking to their favorite locator. It is why I thought I would come up with a tutorial series for CSS Selenium locators to assistance budding automation testers come up with strategic implementation of these locators. And to those of us who are experienced, information technology would be a quick and adept recap.

This commodity will represent the applied implementation of link text & partial link text, as we perform automation testing with Selenium. The links on any web application can aid in locating an element with either exact friction match of the text or through a partial match. Using link text & fractional link text in Selenium, nosotros will be able to locate both of these matches. This is the terminal article of my tutorial serial on CSS Locator in Selenium.

Yous tin can check out other manufactures around different CSS locator in Selenium that helps in locating elements through various ways:

  • ID locator in Selenium
  • Name locator in Selenium
  • Class Name locator in Selenium
  • Tagname locator in Selenium
  • CSS Selector in Selenium
  • XPath in Selenium

If y'all are an advanced or medium Selenium practitioner, then you can chuck on dedicated articles mentioned above. And go for our complete guide to aid you illustrate the applied demonstration of CSS locator in Selenium.

Cheque Out My Consummate Guide For Every CSS Locator In Selenium WebDriver With Examples

With that said, let's observe out how to leverage link text & partial link text in Selenium to locate elements on a web page.

This certification is for anyone who wants to stay alee among professionals who are growing their career in Selenium automation testing.

Here's a short glimpse of the Selenium 101 certification from LambdaTest:

Using Link Text In Selenium To Locate An Element

In social club to admission link using link text in Selenium, the below-referenced lawmaking is used:
driver.findElement(Past.linkText("this is a link text"));

Note: In a scenario where, multiple links having similar text exists, information technology volition automatically select the first one.

Let's refer the code snippet below to understand the utilise instance. In this example, we are taking Airbnb example, where nosotros are clicking on any one stay of Goa through the link match.

selenium locators

Referenced screenshot of the div element with the link text:

selenium locators

We tin can locate the same chemical element using partial link text in Selenium too. Allow's check how!

Using Partial Link Text In Selenium To Locate An Element

Partial link text in Selenium is another way of locating an element via a link. The only deviation from the link text in Selenium to partial link text is that it does non wait into the exact match of the cord value but piece of work on a partial match. And then, in case you lot are looking for a link with a bigger text length, y'all can get away from using only the partial link text rather than the whole link text in Selenium.

Syntax of locating element by fractional link text.

driver.findElement(Past.partialLinkText ("link text"));

Referencing the above scenario, below is the code snippet for partial link text of the aforementioned stay of Airbnb:

How To Select The Right Link Text When You Have Multiple Match Results?

The only thing to think and to be cautious of while using fractional link text in Selenium is when partial link text ends upwardly matching with multiple link text on the page. In this case, make certain, you are clicking on the desired one.

Let's consider another scenario as we perform automation testing with Selenium, where y'all finish upward matching multiple link text and wish to target only the designated one. For the aforementioned homestays of Goa, I am trying to locate the chemical element with partial text as 'pool' in it. So, the strategy would exist to find out domicile many stays have a puddle in them and click on the required stay, post that. The reference lawmaking snippet beneath represents how we can pick the right target out of multiple match results using the fractional link text in Selenium.

selenium locators output

In the to a higher place code snippet, I accept used findElements since I am supposed to receive multiple web elements with partial text as 'pool'. At present, using an index, I take navigated to one of the links, which I wish to click. Elementary, isn't it?

Notation: Both, link text & fractional link text are cases sensitive every bit CSS locator in Selenium.

For example, Presume that a link 'Register' is nowadays on a home page and a similar link 'REGISTER' is present on the footer of the homepage. In this case, if you are locating with link text 'Annals', it volition automatically select the link in the footer and not the other one.

Link text and partial link text locator in Selenium works just on links of a given web application. If you lot intend to locate elements other than links you cannot utilize link text or partial link text locator in Selenium. If y'all are dealing with links in your application, then this is perhaps the best locator to become with. Happy testing! 🙂

Author's Contour

Sadhvi Singh

Sadhvi Singh is a QA Managing director. In 7 years of her professional journey, she has worked on multiple domains and testing techniques similar Automation testing, Database testing, API testing, Manual testing, and Security testing. With multiple tools exposure added to her experience, she has skilled herself farther through her 2 major accolades at International level through ISTQB with foundation and advanced levels.

Examination your websites, web-apps or mobile apps seamlessly with LambdaTest.

  • Selenium, Cypress, Playwright & Puppeteer Testing
  • Existent Devices Deject
  • Native App Testing
  • Appium Testing
  • Live Interactive Testing
  • Smart Visual UI Testing

Book a Demo