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
How to Add Values Dynamically to I18N
Facebook Redirect Url in Ruby on Rails Open Ssl Error
Easiest Way to Convert "A/B/C" to ["A/B/C", "A/B", "A"]
Current Password Can't Be Blank When Updating Devise Account
How to Declare a Two-Dimensional Array in Ruby
Running Capybara Without Rack Produces Errors When Using Url Parameters
Adding Two Activerecord::Relation Objects
Axlsx - Formatting Text Within a Cell
Activerecord Join Table for Legacy Database
Ruby - Append Content at The End of The Existing S3 File Using Fog
Without Converting to a String, How Many Digits Does a Fixnum Have