Get All Links Of Website Home Page

 

// Get All Links Of Website Home Page

import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Links {
	
	public static void main(String[] args) {
		WebDriver driver = new FirefoxDriver();
		driver.get("https://www.google.co.in/");
		List links = driver.findElements(By.tagName("a"));
		System.out.println(links.size());
		for (int i = 1; i<=links.size(); i=i+1)
		{
			System.out.println(links.get(i).getText());
		}
		
	}

}