Link Text and partial link text in Selenium

Selenium is a framework used for testing web applications. It is very efficient and allows browsers to carry out multiple tests. Selenium uses locators to uniquely identify web elements. There are various locators such as ID, name, CSS Selector, and XPath. To locate links on a text page, we can use a link Text locator.

Link Text

Link Text is used to identify <a> tags and can, therefore, extract the hyperlinks from within them. The following code suggests how links can be extracted from within the attached webpage.

Consider the following webpage:

<html>
    <head>
    <title>Educative.io</title>
<body>
    <a href = "https://educative.io"> Visit </a>
    <a href = "https://www.google.com"> Visit </a>
</body>    
</html>    

You can use the following to collect the link for the href on the word “Visit” :

visit_link = driver.find_element_by_link_text('Visit')

Note: Since there are two hyperlinks on similar words, it will return the first hyperlink to the word “Visit”.

Partial Link Text

Link Text is used to identify <a> tags and can, therefore, extract the hyperlinks from within them. Partial Link Text can only be used when a part of the word is added, which enables quicker retrieval for the users.

Consider the following webpage:

<html>
    <head>
    <title>Educative.io</title>
<body>
    <a href = "https://educative.io"> Visit </a>
    <a href = "https://www.google.com"> Google </a>
</body>    
</html>    

You can use the following to collect the link for the href on the word “Visit” :

visit_link = driver.find_element_by_partial_link_text('Vi')

Note: If there are two hyperlinks on similar words, it will return the first hyperlink to the word that contains “Vi”.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved