Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get image details from firefox webdriver?

I've got an image on a page rendered by Firefox via Webdriver, I can get its object (wd.find_element_by_xpath("id('main')/form/p[5]/img")), but how can I get its body either base64-encoded or just a location on my hard drive?

PS: please don't suggest getting the src and fetching it with an external tool. I want the image I already have in the browser.

like image 826
Fluffy Avatar asked Nov 22 '09 12:11

Fluffy


2 Answers

Cached images can be extracted from Firefox's cache by navigating to an URL like this one:

about:cache-entry?client=HTTP&sb=1&key=http://your.server/image.png

The resulting page will contain a line with the "file on disk" label, like this one:

file on disk: /home/fviktor/.mozilla/firefox/7jx6k3hx.default/Cache/CF7379D8d01

This page will also contain the hex dump of the file's contents. You can load the file from that path or parse the hex dump. Please note, that the path can also be none in the case of small files cached only in memory. Your only option is parsing the hex dump in this case.

Maybe there's a way to suppress the hex dump if there's a cache file on the disk, but I'm not sure about it.

like image 103
fviktor Avatar answered Sep 19 '22 23:09

fviktor


I've created a little script for extracting data from browser cache. You can extract cache entries using it. Check it out at this gist. Check this post for usage guide.

like image 44
zxcmehran Avatar answered Sep 20 '22 23:09

zxcmehran