- 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?
We can click a link in Selenium by the following locators along with click() method.
By link text.
By partial link text.
Code Implementation with link text locator.
Example
import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class LinkScripting { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = "https://www.tutorialspoint.com/index.htm"; driver.get(url); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.findElement(By.linkText("Coding Ground")).click(); driver.close(); } }
Code Implementation with partial link text locator.
Example
import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class PartialLinkScripting { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = " https://www.tutorialspoint.com/index.htm"; driver.get(url); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.findElement(By.partialLinkText("Coding")).click(); driver.close(); } }
- Related Articles
- How to click on a link in Selenium with python?
- How to click on a hyper link using linkText in Selenium?
- How to click on a link using Selenium webdriver in Python.
- How to click on a link with a Javascript executor in Selenium with python?
- How to click a link whose href has a certain substring in Selenium?
- How to click on hidden element in Selenium WebDriver?
- How to click on image in selenium webdriver Python?
- How to perform double click on an element in Selenium?
- How to select the text of a span on click in Selenium?
- How to click on across browsers using Selenium Webdriver?
- How to handle a link click event using jQuery?
- How to click on a button with Javascript executor in Selenium with python?
- How to perform right click on an element with Actions in Selenium?
- How to perform double click on an element in Selenium with python?
- How to perform right click on an element in Selenium with python?

Advertisements