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

对于exp:-
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();


这是可行的,但无法滚动,并且由于错误地单击某些内容而在某些时候失败。

最佳答案

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);

09-25 20:25