Scroll down to the bottom of the page with Selenium2?

6,404 views
Skip to first unread message

N.T.

unread,
Mar 27, 2015, 1:35:47 AM3/27/15
to robotframe...@googlegroups.com
In one of my test cases I need to take a screenshot of the entire product page and place it into logs to check if all the images are working.

The problem is the product images only load when you scroll down to them, so if I simply take a page screenshot only the first few "visible" products on the page will be seen. 

Is there any keyword that imitates the "Scroll Down" button and would stop until it reaches the last page? 

I've tried the following workarounds but it didn't work.
1. Click an element at the very bottom of the page before it takes the Capture Page Screenshot.
2. Focus on the element at the bottom of the page before it takes the Capture Page Screenshot.
2. Set the selenium speed slower 

Here's the Script so far:
Go to ${URL} 
Click Element id=trademark //located at the bottom of the page
Capture Page Screenshot

My workaround is to use the Press Key //5A (page down) , and use the Repeat Keyword, but I don't know how to tell it to stop hitting page down until it "sees" the end of the page. 


N.T.

unread,
Mar 27, 2015, 1:44:45 AM3/27/15
to robotframe...@googlegroups.com
Edit:

I just realized that Press Key Native is no longer on the Selenium2 Library. So am back to Square one. 

HelioGuilherme66

unread,
Mar 27, 2015, 7:50:00 PM3/27/15
to robotframe...@googlegroups.com
There is the Press Key keyword which accepts special keys.

I have created a Press Keys keyword which allows to send sequence of keys (typing text) and modified keys with SHIFT, CONTROL or ALT. See it in my fork, https://github.com/HelioGuilherme66/robotframework-selenium2library/tree/expand_press_key

Hélio

HelioGuilherme66

unread,
Mar 27, 2015, 8:31:37 PM3/27/15
to robotframe...@googlegroups.com
I suggest for you to try using PhantomJS (rasterise.js), it takes a full screenshot of your page (you may have to set big vertical size).

Ed Manlove

unread,
Mar 28, 2015, 3:44:31 PM3/28/15
to robotframe...@googlegroups.com
Last time I checked Firefox also takes full page screenshots. Chrome and IE only take what is in the visible portion (IIRC). Note this functionality is browser specific and neither the Selenium2Library nor the Selenium WebDriver has much control over what we get from each browser. (Also IIRC there was some discussion about standardizing this in "selenium 3").

I don't recall needing to scroll myself in any of my tests, so I haven't tried this, but you could try to Focus on an element out of the visible page or scroll via executing some javascript.

Ed

N.T.

unread,
Mar 30, 2015, 3:41:29 AM3/30/15
to robotframe...@googlegroups.com
Hi Helio: Doesn't the Press Key require a locator? To press the key in the specific area of the page? 

Hi Ed

Thank you for your suggestions.

Capture Page screenshot does take the WHOLE page for me on Firefox, but the problem is that I think due to the Angular JS, the product image don't load unless you scroll down to show all items. 

Am sending a screenshot how the product pages look like. 

I took the suggestion about using Javascript, so I ran this code:

Go to ${URL}${PATH}
Execute Javascript window.scrollTo(0,document.body.scrollHeight);
Capture Page Screenshot
Page Should Contain Element ${CSS_Element}

So that it scrolls to the bottom of the page, but because it doesn't scroll through each row of products the product images don't load on the screenshot. 

I'm considering running a javascript function to scroll every couple number of pixels until all products are fully loaded, and then post the screenshot. Would that be possible?

This is the Javascript function am looking into:


Thanks! 
2015-03-30_16-28-24.png

Ed Manlove

unread,
Mar 30, 2015, 6:42:06 AM3/30/15
to robotframe...@googlegroups.com
Interesting. I am assuming that once scrolled onto and then scrolled off those once in view now out of view don't re-disappear. In that case there is a "variable" (forgetting the correct term here?) similar to document.body.scrollHeight which gives you the visible screen height. You could scroll down every visible screen height down to the scroll height...

Ed
--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at http://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

Linh Nguyen

unread,
May 5, 2017, 3:34:23 AM5/5/17
to robotframework-users
Thanks so much, it's so helpful

Vào 14:41:29 UTC+7 Thứ Hai, ngày 30 tháng 3 năm 2015, N.T. đã viết:
Reply all
Reply to author
Forward
0 new messages