Skip to content
Related Articles
Get the best out of our app
Open App

Related Articles

How to Get All Available Links on the Page using Selenium in Java?

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Selenium is an open-source web automation tool that is used to automate web browser testing. The major advantage of using selenium is, that it supports all major web browsers and works on all major Operating Systems, and it supports writing scripts on various languages such as Java,  JavaScript, C# and python, etc. While automating a webpage, we are required to fetch and check all the available links present on the webpage, In this article, we will learn to get all the available links present on a page using “TagName”.

What is Link?

As we know that all the links are of type anchor tag “a” in HTML. For Example,

<a href=””>geeksforgeeks</a>

How to get all available links:

  • Navigate to the webpage.
  • Get the list of WebElements with the TagName “a”.

List<WebElement> links=driver.findElements(By.tagName(“a”));

  • Iterate through the List of WebElements.
  • Print the link text.

Let’s see an Example

In this example, we are navigating to the URL “” and print the link text of all available links on the page.


public class Geeks {
    WebDriver driver = new ChromeDriver();
    // Get all the available Links
    List<WebElement> links
        = driver.findElements(By.tagName("a"));
    // Iterating through all the Links and printing link
    // text
    for (WebElement link : links) {


This program will get all the Links in the List of WebElements and print all the link texts.


My Personal Notes arrow_drop_up
Last Updated : 30 Dec, 2022
Like Article
Save Article
Similar Reads
Related Tutorials