Facebook print list of frineds code not working | Selenium Forum
M
Posted on 21/10/2015
Ashish,
Following code is not working.
There is no error message but it is not printing friends list. Can you please let me know what might be the problem.


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.firefox.FirefoxDriver;

public class Facebook {

public static void main(String[] args) {


WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

driver.get("http://facebook.com");

driver.findElement(By.xpath("//*[@id='email']")).sendKeys("xxxxxxxs");
driver.findElement(By.xpath("//*[@id='pass']")).sendKeys("xxxxxxx");
driver.findElement(By.xpath("//*[@id='u_0_x']")).click();
driver.findElement(By.xpath("//*[@id='pagelet_welcome_box']/ul/li[1]/div/div/a")).click();
driver.findElement(By.xpath("//div[@id='fbTimelineHeadline']/div[2]/div/a[3]")).click();


// All friends //div[@class='clearfix _5qo4']/a

List<WebElement> friends = driver.findElements(By.xpath("//div[@class='clearfix _5qo4']/a"));

System.out.println("Total Friends are ---> " + friends.size());


for (int i=0; i<friends.size(); i++){
System.out.println(friends.get(i).getText());
}


}

}

M
Replied on 23/10/2015

we have made videos of how to do it. check it out.