Write a program to print all link present on google page || selenium code

# Write a program to get all links present on google page


public static void main(String args[])

 {

        // Set the system property for the ChromeDriver  

    System.setProperty("webdriver.chrome.driver","c://desktop//cromedriver.exe");


       // create new instance of ChromeDriver  

   WebDriver driver=new ChromeDriver();


     //launch browser --> open google home page

   driver.get("https://www.google.com");


       // find all links on home page

    List<WebElement> links=driver.findElements(By.tagName("//a"));


          // Iterate through each link and print the href attribute

        for(WebElement link:links)

        {

          String href=link.getAttribute("href").getText();

          System.out.println(href);

        }

          //close the driver

           driver.quit();

}

Comments

Popular posts from this blog