Reputation: 91
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
Reputation: 91
I'm posting my solution which I used for above problem:
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();
Then scroll with below code:
Actions scrollAction = new Actions(groupBrowser);
scrollAction.keyDown(Keys.CONTROL).sendKeys(Keys.END).perform();
Thread.currentThread().sleep(5000);
Upvotes: 4