package book;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
// Covered in Module 16 Google_Page_Navigation.java
public class scroll {
static WebDriver driver;
public static void main(String[] args) throws InterruptedException {
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("http://demoqa.com/accordion/");
driver.manage().window().maximize();
driver.findElement(By.xpath(".//*[@id='ui-accordion-accordion-header-1']")).click();
WebElement element = driver.findElement(By.xpath(".//*[@id='ui-accordion-accordion-panel-1']"));
Long height = (Long) ((JavascriptExecutor) driver).executeScript("return arguments[0].scrollHeight;", element);
System.out.println("The height is " + height.toString());
Long newScrollHeight = 0L;
while(height > newScrollHeight)
{
((JavascriptExecutor) driver).executeScript("return arguments[0].scrollTop = " + newScrollHeight.toString() + ";", element);
newScrollHeight = newScrollHeight + 10;
Thread.sleep(3000);
}
}
}