滚动到特定元素Selenium WebDriver Java [英] Scroll to specific element Selenium WebDriver Java
本文介绍了滚动到特定元素Selenium WebDriver Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Selenium
与 Java
和 ChromeDriver
在网站上运行几个脚本。我想将驱动程序或页面滚动到页面上的特定元素。它可能是可见的。我明白使用 JavascripExecutor
这是可能的,但到目前为止我的方式我只能滚动某些空格。
以下是我所拥有的:
I'm using Selenium
with Java
and ChromeDriver
to run few scripts on a website. I want to scroll the driver or the page to an specific element located on the page. It might be visible. I understand that with a JavascripExecutor
it's possible, but so far the way I'm doing it I can only scroll certain "spaces".
Here is what I have:
jse.executeScript("window.scrollBy(0,250)", "");
推荐答案
如果要滚动到特定元素,你应该尝试使用 scrollIntoView(true)
如下所示: -
If you want to scroll to specific element, you should try using scrollIntoView(true)
as below :-
//Find that specific element first
WebElement element = driver.findElement(..);
//Now scroll to this element
jse.executeScript("arguments[0].scrollIntoView(true);", element);
这篇关于滚动到特定元素Selenium WebDriver Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文