- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to click on a link in Selenium with python?
We can click on a link on page with the help of locators available in Selenium. Link text and partial link text are the locators generally used for clicking links. Both these locators work with the text available inside the anchor tags.
Link Text – The text within the anchor tag is matched with the element to be identified. With this, the first matching element is returned. In case of not matching, NoSuchElementException is thrown.
Partial link Text – The partial text within the anchor tag is matched with the element to be identified. With this, the first matching element is returned. In case of not matching, NoSuchElementException is thrown.
Example
Coding Implementation with link text
from selenium import webdriver #browser exposes an executable file #Through Selenium test we will invoke the executable file which will then #invoke #actual browser driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") # to maximize the browser window driver.maximize_window() #get method to launch the URL driver.get("https://www.tutorialspoint.com/about/about_careers.htm") #to refresh the browser driver.refresh() # identifying the link with the help of link text locator driver.find_element_by_link_text("Company").click() #to close the browser driver.close()
Coding Implementation with partial link text.
from selenium import webdriver #browser exposes an executable file #Through Selenium test we will invoke the executable file which will then #invoke #actual browser driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") # to maximize the browser window driver.maximize_window() #get method to launch the URL driver.get("https://www.tutorialspoint.com/about/about_careers.htm") #to refresh the browser driver.refresh() # identifying the link with the help of partial link text locator driver.find_element_by_partial_link_text("Privacy").click() #to close the browser driver.quit()
- Related Articles
- How to click on a link with a Javascript executor in Selenium with python?
- How to click on a link in Selenium?
- How to click on a link using Selenium webdriver in Python.
- How to click on a hyper link using linkText in Selenium?
- How to click on a button with Javascript executor in Selenium with python?
- How to perform double click on an element in Selenium with python?
- How to perform right click on an element in Selenium with python?
- How to click on image in selenium webdriver Python?
- How to use a click() method in Selenium with python?
- How to click a link whose href has a certain substring in Selenium?
- How to click button Selenium Python?
- How to perform right click on an element with Actions in Selenium?
- Click a href button with Selenium and Python?
- How to click on hidden element in Selenium WebDriver?
- How to perform double click on an element in Selenium?

Advertisements