Save Image in Watir-Webdriver

Save image with watir-webdriver

OpenURI will help you ..

require "watir-webdriver"
require "open-uri"

b = Watir::Browser.new :chrome
b.goto "http://stackoverflow.com/"

File.open("target_file.jpg", 'wb') do |f|
f.write open(b.img(:class, "sponsor-tag-img").src).read
end

Hope you are not doing anything bad.. :)

Please let me know if it helped.

Save image in watir-webdriver

require 'watir-webdriver'    
require 'open-uri'

image_src = @browsers[i].div(:id => 'recaptcha_image').image.src

File.open("/path/", 'wb') do |f|
f.write open(image_src).read
end

Ruby Watir-webdriver saving image when navigating directly to the image

When you do:

$browser.image(:class => "decoded").image.src

You are looking for the html:

<img class="decoded">
<img src="what_you_want"></img>
</img>

I am guessing your html is not like that, hence you get the exception regarding finding the image within the image.

You probably just want the first image with class decoded (remove the second .image):

image_source = $browser.image(:class => "decoded").src

Or maybe you want the full list of images and then get the first one:

image_source = $browser.images(:class => "decoded").first.src

how to save image in blob field using watir?

img=cell.image.src
image = Net::HTTP.get_response(URI.parse(img)).body

save dynamic image from element to disk

You can save a screenshot, if that would help: http://watirwebdriver.com/screenshots/

Getting an image from the cache should be doable from Ruby, but it is not implemented in Watir.



Related Topics



Leave a reply



Submit