scroll up the page to the top in selenium

前端 未结 6 2262
北海茫月
北海茫月 2021-02-19 10:50

How to scroll the webpage to the top of the page.

I know scrolling the page to the bottom is:

window.scrollTo(0,document.body.scrollHeight)
<         


        
6条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-19 11:20

    To scroll to the top of the page

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

    To scroll to the end of the page

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

提交回复
热议问题