- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- 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 using Selenium webdriver in Python.
We can click on a link using Selenium webdriver in Python. A link is represented by the anchor tag. A link can be identified with the help of the locators like - link text and partial link text.
We can use the link text attribute for an element for its identification and utilize the method find_element_by_link_text. With this, the first element with the matching value of the given link text is returned.
driver.find_element_by_link_text("value of link text")
We can also use the partial link text attribute for an element for its identification and utilize the method find_element_by_partial_link_text. With this, the first element with the matching value of the given partial link text is returned.
For both the locators, if there is no element with the matching value of the partial link text/link text, NoSuchElementException shall be thrown.
driver.find_element_by_partial_link_text("value of partial ink text")
Let us see the html code of a webelement −
The link highlighted in the above image has a tagname - a and the partial link text - Refund. Let us try to click on this link after identifying it.
from selenium import webdriver driver = webdriver.Chrome(executable_path='../drivers/chromedriver') #url launch driver.get("https://www.tutorialspoint.com/about/about_careers.htm") #identify link with partial link text l = driver.find_element_by_partial_link_text('Refund') #perform click l.click() print('Page navigated after click: ' + driver.title) #driver quit driver.quit()
- Related Articles
- How to click on a link in Selenium with python?
- How to click on image in selenium webdriver Python?
- How to click on a link in Selenium?
- How to click on a hyper link using linkText in Selenium?
- How to click on across browsers using Selenium Webdriver?
- How to click Allow on Show Notifications popup using Selenium Webdriver?
- How to click on hidden element in Selenium WebDriver?
- How to open a link in new tab using Selenium WebDriver?
- How do you click on an element which is hidden using Selenium WebDriver?
- How to open a link in new tab of chrome browser using Selenium WebDriver?
- Selenium Webdriver submit() vs click().
- How to use Selenium webdriver to click google search?
- How to click a link whose href has a certain substring in Selenium?
- How to refresh a webpage using Python Selenium Webdriver?