Wednesday 7 August 2013

Extracting friends list in your facebook account using Selenium

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 facebook_friends_list {


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

WebDriver dr =new  FirefoxDriver();
dr.get("http://facebook.com");

dr.findElement(By.xpath(".//*[@id='email']")).sendKeys("*******");
dr.findElement(By.xpath(".//*[@id='pass']")).sendKeys("******");
dr.findElement(By.xpath(".//*[@type='submit']")).click();
dr.findElement(By.xpath("//a[text()='Sudhakar']")).click();
Thread.sleep(10000L);
dr.findElement(By.xpath("//a[text()='Friends']")).click();
//dr.findElement(By.xpath("html/body/div[3]/div[1]/div/div/div[1]/div/div[1]/ul/li[4]/a")).click();
Thread.sleep(10000L);
WebElement  fr=dr.findElement(By.xpath("//*[@id='collection_wrapper_2356318349']/div"));
   List<WebElement> friends_list=fr.findElements(By.tagName("a"));
  // System.out.println(friends_list.size());
        for(int i=0;i<friends_list.size();i++){

System.out.println(friends_list.get(i).getText());

}

No comments:

Post a Comment