Toggle navigation
Home
(current)
Selenium Training
Course Details
Free Videos
Support Forum
QTP UFT Training
Course Details
Free Videos
Support Forum
Appium Training
Course Details
Free Videos
Support Forum
Contact Us
(current)
All Courses
(current)
Login
(current)
Avail Discount
Name
Email
Phone Number
Tools
Selenium
QTP/UFT
Appium
Enroll Now
Home
Forum
Selenium Forum
Facebook frinds name print using java script to scroll down
Facebook frinds name print using java script to scroll down
M
Posted on 05/09/2015
mport java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class facebook_friends {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "D:\\Selenium\\Driver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.facebook.com/");
driver.manage().window().maximize();
driver.findElement(By.xpath("//input[@type='email']")).sendKeys("xxxx@gmail.com");
driver.findElement(By.xpath("//input[@type='password']")).sendKeys("xxxxx");
driver.findElement(By.xpath("//input[@value='Log In']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//a[@class='fbxWelcomeBoxName']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//a[@data-tab-key='friends']")).click();
String h = driver.findElement(By.xpath("/html/body/div[1]/div[2]/div[1]/div/div[2]/div[2]/div[2]/div/div[1]/div/div[3]/div/div[2]/div[2]/div/a[3]/span[1]")).getText();
int count = Integer.valueOf(h);
System.out.println(count);
int y=0;
String url = driver.getCurrentUrl();
driver.navigate().to(url);
while(count > y){
((JavascriptExecutor) driver)
.executeScript("window.scrollTo(0, document.body.scrollHeight)");
Thread.sleep(5000);
List<WebElement> element = driver.findElements(By.xpath("//li[@class='_698']/div/div/div[2]/div/div[2]/div/a"));
Thread.sleep(5000);
y = element.size();
System.out.println(y);
}
List<WebElement> element2 = driver.findElements(By.xpath("//li[@class='_698']/div/div/div[2]/div/div[2]/div/a"));
System.out.println(element2.size());
for(int k=0;k<element2.size();k++){
System.out.println(element2.get(k).getText());
}
}
}
M
Replied on 06/09/2015
what is the problem you are getting?