Happy New Year 2015

sydney-new-years-eve2

Advertisements

Counting number of links on a website

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;
import org.openqa.selenium.firefox.FirefoxDriver;

public class countnolinks {
private static String[] link=null;
private static int linkcount=0;
public static WebDriver driver;

public static void main(String[] args)throws NullPointerException
{

System.setProperty(“webdriver.chrome.driver”, “C:\\eclipse\\Jarfiles\\jars\\chromedriver.exe”);
//driver=new FirefoxDriver();
driver= new ChromeDriver();
driver.get(“http://www.bing.com”);
driver.manage().timeouts().implicitlyWait(100,TimeUnit.SECONDS);

List<WebElement>lnks=driver.findElements(By.xpath(“//a”));

linkcount=lnks.size();

System.out.println(lnks.size());

System.out.printf(“total no of links available” +linkcount);

String[] link = new String[linkcount];

System.out.println(“list of links available”);
// System.out.println(link);
// print all links from web page
System.out.println(linkcount);

for(int i=0; i<linkcount; i++)
{
System.out.println(lnks.get(i).getText());
}
driver.quit();

}

}