Here is how you can find all the Links on a Webpage with Selenium WebDriver in Java.

All you need to do is to create a list of all WebElements, and then iterate thorough the list of links to print the link and the text of the link:

List allLinks = driver.findElements(By.tagName("a"));

System.out.println("All links found on web page are: " + allLinks.size() + " links");

for (WebElement link : allLinks) {

//print the links i.e. or

//print the links text

To get the link you can call the “getAttribute” method on the link WebElement passing “href” as its argument which will print the links as i.e. or

Use our older post in order to understand how you can find WebElements on a webpage with Selenium WebDriver.

In order to click on each link element and the go back you can use the following WebDriver code:

for (WebElement link : allLinks) {;
} is a cloud testing platform: