首页 文章

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

提问于
浏览
1

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

对于exp: - https://groups.google.com/forum/#!forum/ibm.software.websphere.application-server

  • 需要"scroll the contents down"

尝试: -

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 回答

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

相关问题