Dashboard > Watir > ... > Simple Examples > Save All Images on a Webpage
Watir Log In View a printable version of the current page.
Save All Images on a Webpage
Added by Alan Baird, last edited by Alister Scott on Sep 29, 2008
Labels: 
(None)

Save All Images on a Webpage

If you need to save all of the images from a webpage you can take advantage of the save method in Watir::Image. This is really easy to do as you can see in the code below.

require 'watir'

browser = Watir::IE.new
browser.goto('http://twitter.com')

idx = 0

# using the images collection, iterate through all of the images on a page
browser.images.each do |x|
  idx += 1
  # apparently the string accepted by the string method will not allow variable substitution
  location = 'c:\tmp\file-' + idx.to_s + '.jpg'
  x.save(location)
end

Site running on a free Atlassian Confluence Community License granted to OpenQA. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.6 Build:#812 Aug 06, 2007) - Bug/feature request - Contact Administrators