Wednesday, March 6, 2019

Count all the links and display in Selenium Webdriver

 package learning;  
 import java.util.List;  
 import java.util.concurrent.TimeUnit;  
 import org.openqa.selenium.By;  
 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.WebElement;  
 import org.openqa.selenium.chrome.ChromeDriver;  
 public class CountElements {  
      public static void main(String[] args) {  
           System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");  
           WebDriver driver = new ChromeDriver();  
           driver.manage().window().maximize();  
           driver.manage().deleteAllCookies();  
           driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);  
           driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);  
           driver.get("https://www.facebook.com/");  
           List<WebElement> list = driver.findElements(By.tagName("a"));  
           System.out.println(list.size());  
           for (int i = 0; i < list.size(); i++) {  
                String links = list.get(i).getText();  
                System.out.println(links);  
           }  
      }  
 }  

No comments:

Post a Comment