使用Selenium WebDriver在网页内滚动特定DIV

时间:2015-04-21 06:43:16

标签: java selenium

如何使用Selenium WebDriver在网页内滚动特定的DIV?不滚动整个网页,但滚动网页内的特定DIV。

表示: - https://groups.google.com/forum/#!forum/ibm.software.websphere.application-server

  • 需要"向下滚动内容"

尝试: -

Actions act2 = new Actions(browser);
WebElement draggablePartOfScrollbar=browser.findElement(By.className("G3J0AAD-b-F"));
act2.moveToElement(draggablePartOfScrollbar).clickAndHold().moveByOffset(0, 250).release().build().perform();

这是有效的,但这不是滚动,有时会错误地点击某些内容而失败。

1 个答案:

答案 0 :(得分:2)

i am posting my solution which i used for above problem:-

1) first click on the scroll-able pane of your page:-

Actions clickAction = new Actions(groupBrowser);
        WebElement scrollablePane = groupBrowser.findElement(By
                .className("G3J0AAD-b-F"));
        clickAction.moveToElement(scrollablePane).click().build().perform();

2) then scroll with below code:-

            Actions scrollAction = new Actions(groupBrowser);
            scrollAction.keyDown(Keys.CONTROL).sendKeys(Keys.END).perform();
            Thread.currentThread().sleep(5000);