向上滚动页面到硒顶部 [英] scroll up the page to the top in selenium
本文介绍了向上滚动页面到硒顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将网页滚动到页面顶部.
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)
就像那样,可以将页面滚动到顶部
just like that is it possible to scroll the page to the top
推荐答案
要滚动到页面顶部,只需滚动到0, 0
:
To scroll to the top of the page, just scroll to the 0, 0
:
window.scrollTo(0, 0);
或者,作为替代选择,您可以滚动到视图中或header
元素(或顶部的其他元素):
Or, as an alternative option, you can scroll into view of the header
element (or some other element on top):
WebElement element = driver.findElement(By.tagName("header"));
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].scrollIntoView();", element);
这篇关于向上滚动页面到硒顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文