How to find Elements by Link Text using Selenium?

Find Elements by Link Text

To find the link elements (hyperlinks) by the value (link text) inside the link, using Selenium in Python, call find_elements() method, pass By.LINK_TEXT as the first argument, and the link text as the second argument.

find_elements(By.LINK_TEXT, "link_text_value")

find_elements() method returns all the HTML Elements, that match the given link text, as a list.

If there are no elements by given link text, find_elements() function returns an empty list.


Consider the HTML document at the URL, with the following HTML content.

HTML Webpage

  <p>Paragraph 1</p>
  <div name="xyz">
    <p>Article 1</p>
    <a href="/tmp/article-1/">Read More</a>
  <div name="xyz">
    <p>Article 2</p>
    <a href="/tmp/article-2/">Read More</a>

In the following Python program, we will find all the HTML elements that have link text 'Read More', and print those elements to the console.

Python Program (Selenium)

from selenium import webdriver
from import ChromeDriverManager
from import Service as ChromeService
from import By

# Setup chrome driver
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))

# Navigate to the url

# Find elements by Link Text
my_elements = driver.find_elements(By.LINK_TEXT, 'Read More')
for element in my_elements:

# Close the driver


<a href="/tmp/article-1/">Read More</a>
<a href="/tmp/article-2/">Read More</a>


In this Python Selenium tutorial, we learned how to find all the elements that have given link text, in the webpage, using Selenium.

Related Tutorials

Quiz on Selenium

Q1. What is Selenium Python used for?

Not answered

Q2. Which of the following is not a popular web driver used in Selenium Python?

Not answered

Q3. Which of the following is not a method to wait for a web element to load in Selenium Python?

Not answered

Q4. Which of the following is not a commonly used assertion method in Selenium Python?

Not answered

Q5. Which of the following is not a commonly used web element locator in Selenium Python?

Not answered
Code copied to clipboard successfully 👍