Re: how to scroll down page with web driver

1,562 views
Skip to first unread message

Mike Riley

unread,
Sep 11, 2012, 1:07:05 PM9/11/12
to webd...@googlegroups.com
First, why do you need to scroll down?  Selenium will scroll automatically to any element that it needs to interact with.

What are you trying to accomplish by scrolling?

Mike

On Tuesday, September 11, 2012 5:12:00 AM UTC-7, Nagarjuna Reddy K wrote:
Hi

Can any one give me information regarding how to scroll down page using web driver .Actually i have used  below code for  face book to scroll down page ,it's executing but page is not scroll downed. Here is the problem with coordinates i am using or any thing else .Give me any suggestions regarding this

  JavascriptExecutor js = (JavascriptExecutor) driver;
  js.executeScript("javascript:window.scrollBy(0,8000)");

Thank you,
Nagarjuna

Mike Riley

unread,
Sep 13, 2012, 1:13:02 PM9/13/12
to webd...@googlegroups.com
That would scroll it all right.

So your page only makes that element visible when it is in the viewable section of the page?  Is it that animated ad that pops up at the bottom?

I am not certain, but I think if you were to set the focus on some element near the bottom Selenium would scroll down there and make it visible for you.

Mike

On Thursday, September 13, 2012 3:33:59 AM UTC-7, Erik Winter wrote:

I needed to scroll like that for a particular case where the element was hidden until the user scrolls down, see the bottom bar at http://www.c1000.nl/ for example.

I used the follwing code to solve this (java):

JavascriptExecutor js = (JavascriptExecutor) this.driver;
js.executeScript("window.scrollTo(0, document.body.scrollHeight); return true");

Hope this helps,

Erik Winter

Op dinsdag 11 september 2012 19:07:05 UTC+2 schreef Mike Riley het volgende:

Erik Winter

unread,
Sep 14, 2012, 8:17:29 AM9/14/12
to webd...@googlegroups.com

The ad is a bit annoying and confusing, I meant the grey bar underneath. It is present on all pages, for example also here: http://www.c1000.nl/koken.aspx The site is for a food retailer and clicking on "Boodschappenlijst" pops up some shopping list functionality.

Initially, the elements are present, but hidden by CSS. They are animated into the window as soon as the user scrolls down. It is functionality that is always available, but the designers didn't want it to be part of the first impression of the site/page, I suppose. Because the elements are hidden, I could not let Selenium click on them. I did not try to focus the element, I went directly with scrolling by javascript, since that is what a user would do. It is part of the use case.

Erik Winter

Op donderdag 13 september 2012 19:13:02 UTC+2 schreef Mike Riley het volgende:

Mike Riley

unread,
Sep 14, 2012, 7:01:31 PM9/14/12
to webd...@googlegroups.com
I looked at it with Firebug and those elements seem to be staying the same.  But if you click on the shopping list link (or the arrow) WebDriver should scroll down to those elements and make the list appear at the same time.  You would just need to check after doing the click that the element you want from the list is visible.

I would worry about the scrolling, too.  Since what you want may be visible, but moving.  I am not sure if that would be a problem or not.

If you don't want to click on it, you should be able to do a moveTo() and still have WebDriver do the scrolling for you (I think).

Mike
Reply all
Reply to author
Forward
0 new messages