Last modified: Jan 02, 2024 By Alexander Williams
Python Selenium: Find Element by Link Text - Examples
Example 1: Find Element by Link Text
from selenium import webdriver
# Create a Chrome driver
driver = webdriver.Chrome()
# Navigate to a webpage
driver.get('https://example.com')
# Find an element by its link text
element = driver.find_element_by_link_text('Example Link')
# Perform an action on the selected element
element.click()
Output: N/A
Example 2: Find Element by Partial Link Text
# Continue from the previous example
# Find an element by partial link text
partial_element = driver.find_element_by_partial_link_text('Partial Link')
# Perform an action on the element found by partial link text
partial_element.click()
Output: N/A
Example 3: Find Elements by Link Text (Multiple Elements)
# Continue from the first example
# Find multiple elements by link text
elements = driver.find_elements_by_link_text('Example Link')
# Loop through the elements and perform actions
for element in elements:
element.click()
Output: N/A