- 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 GetPageLinks {
-
- public static void main(String[] args) {
- WebDriver driver = new FirefoxDriver();
- driver.get("http://www.c-sharpcorner.com");
- List<WebElement> no = driver.findElements(By.tagName("a"));
- int numberoflinks = no.size();
- System.out.println("Total number of links available is: "+numberoflinks);
- for(WebElement pagelink : no) {
- String linktext = pagelink.getText();
- String link = pagelink.getAttribute("href");
- System.out.println(linktext+" -> "+link);
- }
- }
- }
Output
Total number of links available is: 342 and also print their respective links.