# How to click on a link in Selenium with python?

Selenium Web DriverAutomation TestingSoftware Testing

#### React Full Stack Web Development With Spring Boot

67 Lectures 4.5 hours

#### The Complete Selenium WebDriver with Java Course

192 Lectures 20 hours

#### Fundamentals of React and Flux Web Development

48 Lectures 10.5 hours

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

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
#to refresh the browser
driver.refresh()
#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.quit()