Selenium Webdriver,在div弹出窗口内滚动 [英] Selenium Webdriver, scrolling inside a div popup
本文介绍了Selenium Webdriver,在div弹出窗口内滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
显示一个弹出窗口,其内容很大,必须滚动才能完全查看。是否有滚动div中显示为弹出窗口的内容。我们可以使用JavaScriptExecutor滚动到Element,但这似乎只能在窗口级别工作,但不能在div级别工作。
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.
推荐答案
// 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);
这应该有助于在DIV元素中滚动。
This should help to scroll within DIV element.
这篇关于Selenium Webdriver,在div弹出窗口内滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文