Java Selenium Webdriver,在 div 弹出窗口内滚动

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22709200/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 17:24:47  来源:igfitidea点击:

Selenium Webdriver, scrolling inside a div popup

javaselenium-webdriver

提问by Prabhu R

There is a pop that is displayed which has a content that large that will have to scroll to view it completely. Is there was to scroll the content within the div that is shown as a popup. We can use the JavaScriptExecutor to do scroll to Element, but that seems to work only at the window level but not at the div level.

有一个弹出窗口,其内容很大,必须滚动才能完全查看。是否要滚动显示为弹出窗口的 div 中的内容。我们可以使用 JavaScriptExecutor 滚动到 Element,但这似乎只能在窗口级别工作,而不能在 div 级别工作。

回答by Sitam Jana

// Initialize Javascript executor
JavascriptExecutor js = (JavascriptExecutor) driver;

// Scroll inside web element vertically (e.g. 100 pixel)
js.executeScript("arguments[0].scrollTop = arguments[1];",driver.findElement(By.id("<div-id>")), 100);

This should help to scroll within DIV element.

这应该有助于在 DIV 元素内滚动。