Re: [selenium-users] Save image from page to disk.

2,658 views
Skip to first unread message

Maxim Vorobev

unread,
Apr 9, 2013, 3:55:32 AM4/9/13
to selenium-users
You can
1. Grab full-page screenshot
2. Get WebElement position
3. Get WebElement dimension
4. Crop WebElement image from page screenshot
5. Save WebElement image to disk
:)



On Tue, Apr 9, 2013 at 9:02 AM, Юрий Бушев <bush...@gmail.com> wrote:
Hi All!

I have the following trouble, I want to save image, which is already presented on the page in FireFox driver to the disk.

Image are placed between tags <img id="image"> with known id.

I could not get image by "src" link. Because image will change by "src" script.

How I can get data of this image with Selenium and Java? May be I can take a screenshot only of wanted DOM element?

--
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.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/MGCB8jzLimgJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

David Lai

unread,
Apr 9, 2013, 12:29:22 PM4/9/13
to seleniu...@googlegroups.com
Something I have on my todo list (WTFramework) is figure out how to leverage the JS code in this framework for taking screenshots for individual webelements. 

In theory,an element can be written to an HTML canvas, which then can have it's data encoded to base64 using javascript, then returned back via webdriver.executeScript() call.  

David

unread,
Dec 3, 2013, 9:33:14 PM12/3/13
to seleniu...@googlegroups.com
What Maxim describes, implemented as (Java) code can be seen here:


for other languages, the code will differ, though the Selenium APIs called will remain the same.

Andreas Tolfsen

unread,
Dec 4, 2013, 6:33:43 AM12/4/13
to seleniu...@googlegroups.com

mang...@gmail.com writes:

> On Tuesday, April 9, 2013 12:55:32 AM UTC-7, Maxim wrote:
>>
>> You can
>> 1. Grab full-page screenshot
>> 2. Get WebElement position
>> 3. Get WebElement dimension
>> 4. Crop WebElement image from page screenshot
>> 5. Save WebElement image to disk

Please note that Selenium isn't designed for this purpose. A much
better approach if you indeed need to save an image to disk (I'm not
sure why you'd want to do that), getting the img element's src attribute
from Selenium, and passing this on to curl or wget would be a much
better approach.
Reply all
Reply to author
Forward
0 new messages