<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog &#187; watir</title>
	<atom:link href="http://blog.cliffano.com/tag/watir/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.cliffano.com</link>
	<description>Geeking, Living, Travelling</description>
	<lastBuildDate>Thu, 26 Jan 2012 10:18:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Image Saving In Watir</title>
		<link>http://blog.cliffano.com/2008/12/30/image-saving-in-watir/</link>
		<comments>http://blog.cliffano.com/2008/12/30/image-saving-in-watir/#comments</comments>
		<pubDate>Mon, 29 Dec 2008 18:03:25 +0000</pubDate>
		<dc:creator>Cliffano Subagio</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[watir]]></category>

		<guid isPermaLink="false">http://blog.cliffano.com/?p=434</guid>
		<description><![CDATA[So I got the chance to use Watir again on a short project at work. The last time I used it was about 1.5 years ago, and I was glad to find out that Watir is still a nice library to use. Watir simply works without much hassle. The only issue I had was with [...]]]></description>
			<content:encoded><![CDATA[<p>So I got the chance to use <a href="http://wtr.rubyforge.org/">Watir</a> again on a short project at work. The last time I used it was about 1.5 years ago, and I was glad to find out that Watir is still a nice library to use. Watir simply works without much hassle.</p>
<p>The only issue I had was with <a href="http://wiki.openqa.org/display/WTR/Save+All+Images+on+a+Webpage">image saving</a>. From <a href="http://wtr.rubyforge.org/rdoc/classes/Watir/Image.html">Image class documentation</a> (Watir 1.6), it wasn&#8217;t obvious that save can only be called when image element is directly contained within a browser element.</p>
<p>I was trying to save the first image within a div,</p>
<pre class="brush: ruby; title: ; notranslate">
$browser.div(:id, 'foobar').images[1].save('d:\\temp')
</pre>
<p>which resulted in this error</p>
<pre class="brush: plain; title: ; notranslate">
NoMethodError: undefined method `goto' for #&lt;Watir::Div:0x3fa5d7c&gt;
d:/dev/ruby/lib/ruby/gems/1.8/gems/watir-1.6.2/lib/watir/image.rb:113:in `save'
</pre>
<p>Looking at the implementation of save in <a href="http://svn.openqa.org/fisheye/browse/watir/trunk/watir/lib/watir/image.rb?r=1662">image.rb</a>,</p>
<pre class="brush: ruby; title: ; notranslate">
def save(path)
  require 'watir/windowhelper'
  WindowHelper.check_autoit_installed
  @container.goto(src)
  begin
    thrd = fill_save_image_dialog(path)
    @container.document.execCommand(&quot;SaveAs&quot;)
    thrd.join(5)
  ensure
    @container.back
   end
end
</pre>
<p>it shows that save relies on the existence of goto and back methods within the container of the element, meaning that calling save method will tell the browser to go to the image src value, save it, and then click the back button. Hence image must be contained directly within a browser element.</p>
<p>I ended up having to use XPath because the image element doesn&#8217;t have any id or class that allows me to directly reference it from a browser element.</p>
<pre class="brush: ruby; title: ; notranslate">
$browser.image(:xpath, &quot;//div[@id='foobar']/img&quot;).save(&quot;d:\\temp&quot;)
</pre>
<p>It would be nicer if @container can be replaced by something like find_root_container or something that traverses the ancestor container elements and eventually finds a browser element.</p>
<p>Another nice improvement to the save method implementation would be instead of going to the image src and then clicking back, which could potentially lose the state of a page, it would be nicer to open a new window and close it afterward.</p>

<p class="FacebookLikeButton"><fb:like href="http%3A%2F%2Fblog.cliffano.com%2F2008%2F12%2F30%2Fimage-saving-in-watir%2F" layout="standard" show_faces="false" width="450" action="like" colorscheme="light"></fb:like></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cliffano.com/2008/12/30/image-saving-in-watir/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

