himukr
himukr

Reputation: 91

Scroll a specific DIV inside a webpage using Selenium WebDriver

How can we scroll a specific DIV inside a webpage using Selenium WebDriver ? NOT scrolling the complete webpage, BUT scrolling a specific DIV inside the webpage.

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

tried:-

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

This is working but this is not scrolling and it fails sometime by mistakenly clicking some content.

Upvotes: 3

Views: 4781

Answers (1)

himukr
himukr

Reputation: 91

I'm 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);
    

Upvotes: 4

Related Questions