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

前端 未结 2 1220
予麋鹿
予麋鹿 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:51

    We have to use JavascriptExecutor

    To scroll using coordinate

    ((JavascriptExecutor) driver).executeScript("window.scrollBy(0,500)");
    

    To scroll till end of the page

    ((JavascriptExecutor) driver)
         .executeScript("window.scrollTo(0, document.body.scrollHeight)");
    

    To scroll till any element

    ((JavascriptExecutor) driver).executeScript(
                "arguments[0].scrollIntoView();", element);
    

提交回复
热议问题