How to scroll down the page till bottom(end page) in the Selenium WebDriver

前端 未结 2 1222
予麋鹿
予麋鹿 2021-02-07 03:16

I need to scroll down page till end in the Selenium WebDriver. I tried to scroll down the page by using the following code snippet:

JavascriptExecutor jse6 = (Ja         


        
2条回答
  •  北荒
    北荒 (楼主)
    2021-02-07 03:56

    For this you can take the xpath of any object at the end of the page manually.And use the below code.

    WebElement lastElement = 
    driver.findElement(By.xpath("//a[@title='org.apache.spark download']"));
    int y = lastElement.getLocation().getY();
    JavascriptExecutor js = (JavascriptExecutor)driver;
    js.executeScript("window.scrollTo(0,"+y+")");
    Thread.sleep(3000);
    

提交回复
热议问题