How to scroll a specific DIV using Selenium WebDriver?

7,777 views
Skip to first unread message

Satyakam Mishra

unread,
Jan 4, 2013, 9:03:41 AM1/4/13
to seleniu...@googlegroups.com
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.

Please help.

Shaba K

unread,
Jan 4, 2013, 11:25:37 AM1/4/13
to seleniu...@googlegroups.com
Can't you achieve by passing xpath to access that DIV


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/P8DK2gTPf5QJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Raman Rana

unread,
Aug 22, 2013, 2:34:59 AM8/22/13
to seleniu...@googlegroups.com
Brother he is asking code for scrolling a particular div not the whole page. And the code you have pasted will scroll the whole page. Please don't misguide persons.

On Friday, January 4, 2013 10:58:06 PM UTC+5:30, venkat paloju wrote:
Hi Mishra,

Please try the following code...

if(driver instanceOf JavaScriptExecutor){
((JavaScriptExecutor)driver).executeScript("scroll(0,250);");
}
This will scroll down vertically.

Thanks,
Chary.

Mark Collin

unread,
Aug 22, 2013, 5:28:40 AM8/22/13
to seleniu...@googlegroups.com
You are talking about some reasonably involved JavaScript here and you have been give a sane attempt at a solution.  I would classify this as best offort, not misdirection (Hell if we shouted at everybody who didn't supply the correct answer first time in this list there would be a lot of shouting going on).

Have a look at this:

https://github.com/flesler/jquery.scrollTo

It's the code for the jQuery implementation of ScrollTo which supports scrolling inside divs.  Have fun reverse engineering it :)
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.

Mat Walker

unread,
Apr 7, 2015, 12:14:10 AM4/7/15
to seleniu...@googlegroups.com
What was the part in "NOT scrolling the complete webpage" that was not understood?


On Saturday, 5 January 2013 03:28:06 UTC+10, venkat paloju wrote:
Hi Mishra,

Please try the following code...

if(driver instanceOf JavaScriptExecutor){
((JavaScriptExecutor)driver).executeScript("scroll(0,250);");
}
This will scroll down vertically.

Thanks,
Chary.

On Friday, 4 January 2013 19:33:41 UTC+5:30, Satyakam Mishra wrote:

fletch

unread,
Apr 7, 2015, 11:39:21 AM4/7/15
to seleniu...@googlegroups.com
The below will scroll within a div       

        String st = "cssselector";
        String s = String.format("var topPos = document.querySelector(\""+st+"\"); topPos.scrollIntoView(false); ");
        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript(s);

ramit sharma

unread,
Mar 30, 2019, 12:20:22 AM3/30/19
to Selenium Users
Hi Raman,

I am trying to scroll in the left pane of https://news.google.com/?hl=en-CA&gl=CA&ceid=CA:en and scrolling to the bottom of it and then clicking help link. I am trying to use the div of the left pane and using below code but it does not seem to work. Can you please help :-
1. WebElement leftPaneElement = driver.findElement(By.xpath("//*[@id='gb']/div[4]/div[2]/div/c-wiz/div"));
Actions act = new Actions(driver);
act.moveToElement(leftPaneElement);
                 js.executeScript("window.scrollTo(0,document.body.scrollHeight)");
2. Also tried using :-
     WebElement leftPaneElement = driver.findElement(By.xpath("//*[@id='gb']/div[4]/div[2]/div/c-wiz/div"));
     js.executeScript("arguments[0].scrollIntoView(true);", leftPaneElement);
     js.executeScript("window.scrollTo(0,document.body.scrollHeight)");

In both the cases, it is scrolling the main page only to the bottom.
Reply all
Reply to author
Forward
0 new messages