how can save website images watir, without reloading them open-uri or similar?
i: reason why can't use
file.open(file_name, 'wb') |f| f.write open(img.src).read end # file open
is images generated in current (login-)session , once, "external" 2nd access isn't possible.
ii: browser.images.save()
- ie - isn't helpful either, opens save-to dialogue. useless automation.
examples: http://wiki.openqa.org/display/wtr/save+all+images+on+a+webpage
require 'watir' browser = watir::browser.new :ie browser.goto 'http://google.com' idx = 0 browser.images.each |x| puts idx idx += 1 location = 'c:\tmp\file-' + idx.to_s + '.jpg' x.save(location) end
github source: http://rubydoc.info/github/watir/watir-classic/watir/image
# file 'lib/watir-classic/image.rb', line 48 def save(path) @container.goto(src) begin fill_save_image_dialog(path) @container.document.execcommand("saveas") ensure @container.back end end
my best idea atm fetch images using proxy. maybe there "watir-way".
environment:
# ruby 1.9.3p125 (2012-02-16) [i386-mingw32] # watir (4.0.2 x86-mingw32) # watir-classic (3.6.0, 3.5.0, 3.4.0) # watir-webdriver (0.6.4, 0.6.2)
edit: aware there different ways images website, , without event thinking build list solutions, solve problem watir.
you may want consider disabling images on browser being controlled watir. can find urls in source , fetch images first time using code. net effect should same you're trying do.
Comments
Post a Comment