<?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>Huddled Masses &#187; WatiN</title>
	<atom:link href="http://huddledmasses.org/tag/watin/feed/" rel="self" type="application/rss+xml" />
	<link>http://huddledmasses.org</link>
	<description>You can do more than breathe for free...</description>
	<lastBuildDate>Sat, 28 Jan 2012 21:37:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<cloud domain='huddledmasses.org' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>Did you know PowerShell can use Selenium?</title>
		<link>http://huddledmasses.org/did-you-know-powershell-can-use-selenium/</link>
		<comments>http://huddledmasses.org/did-you-know-powershell-can-use-selenium/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 05:46:42 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Automation]]></category>
		<category><![CDATA[Browser]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Selenium]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[WatiN]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1789</guid>
		<description><![CDATA[This is sort-of a place-holder for a full-length post that I really ought to write about driving web testing from PowerShell using Selenium. I actually have a little module around for doing that with WaTiN, but honestly the Selenium project seems to be a lot more active, and has quite a bit of muscle behind [...]]]></description>
			<content:encoded><![CDATA[	<p>This is sort-of a place-holder for a full-length post that I really ought to write about driving web testing from PowerShell using Selenium.  I actually have a little module around for doing that with WaTiN, but honestly the Selenium project seems to be a lot more active, and has quite a bit of muscle behind it since they&#8217;ve merged with WebDriver&#8230;</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">Type</span></span> <span style="color: #000066;">-path</span> ~\Downloads\selenium<span style="color: #66cc66;">-</span>dotnet<span style="color: #66cc66;">-</span>2.16.0\net40\WebDriver.<span style="color: #003366;">dll</span> <br />
<br />
<span style="color: #666666; font-style: italic;"># Navigate to google in IE (or Firefox, Chrome, Opera, etc)</span><br />
<span style="color: #660033; font-weight: bold;">$driver</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Object</span></span> OpenQA.<span style="color: #003366;">Selenium</span>.<span style="color: #003366;">IE</span>.<span style="color: #003366;">InternetExplorerDriver</span> <br />
<span style="color: #660033; font-weight: bold;">$driver</span>.<span style="color: #003366;">Url</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;http://google.com&quot;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># Type PowerShell into the query box, the page will update via AJAX</span><br />
<span style="color: #666666; font-style: italic;"># Note we won't hit enter or anything</span><br />
<span style="color: #660033; font-weight: bold;">$q</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$driver</span>.<span style="color: #003366;">FindElementByname</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;q&quot;</span><span style="color: #333;">&#41;</span> <br />
<span style="color: #660033; font-weight: bold;">$q</span>.<span style="color: #003366;">SendKeys</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;PowerShell&quot;</span><span style="color: #333;">&#41;</span> <br />
<br />
<span style="color: #666666; font-style: italic;"># Use a CSS selector to find the first result link and click it</span><br />
<span style="color: #660033; font-weight: bold;">$driver</span>.<span style="color: #003366;">FindElementByCssSelector</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;li.g h3.r a&quot;</span><span style="color: #333;">&#41;</span>.<span style="color: #003366;">Click</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
&nbsp;</div>

	<h3>One Catch</h3>

	<p><a href="http://joelbennett.net/wordpress/wp-content/uploads/2012/01/ProtectedMode.png" style="float:right; padding-left: 1em; "><img src="http://joelbennett.net/wordpress/wp-content/uploads/2012/01/ProtectedMode.png" alt="The Security tab of the Internet Options dialog" title="ProtectedMode" width="423" height="541" class="size-full wp-image-1796" /></a>If you try this with IE and you get the error <em>Unexpected error launching Internet Explorer. Protected Mode must be set to the same value (enabled or disabled) for all zones</em> ... it means exactly what it says.  You need to open &#8220;Internet Options&#8221; from your start menu (or from IE), and go through each &#8220;zone&#8221; and set the &#8220;Enabled Protected Mode&#8221; check box to the same value for each zone (either all checked, obviously the most secure, or all unchecked).  I&#8217;m not going to debate whether setting them all <em>unprotected</em> is a good idea &#8230; I set mine to all protected, but I don&#8217;t generally use IE anyway. </p>

	<p>If you want more help, Selenium&#8217;s documentation is great, and there&#8217;s a section on <a href="http://seleniumhq.org/docs/03_webdriver.html#getting-started-with-selenium-webdriver">Getting Started with Selenium WebDriver</a> which I found quite helpful (make sure your examples are in &#8220;csharp&#8221; and you can almost just copy and paste &#8212; someone should offer to do them in PowerShell).  </p>

	<p>If you want more information about the Internet Explorer driver and this problem in particular, the short answer is that &#8220;Protected Mode&#8221; is a security boundry, so if you cross over it the <span class="caps">COM</span> automation object doesn&#8217;t work &#8212; thus, you need to make sure you always stay on the same side. There&#8217;s a good discussion <a href="http://code.google.com/p/selenium/issues/detail?id=1795">on the mailing list archive</a> about how it works and why, as well a weird alternative <a href="http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/ie/InternetExplorerDriver.html#INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS">documented on the Selenium JavaDocs</a></p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/did-you-know-powershell-can-use-selenium/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Convert Twitter users into FriendFeed Imaginary Friends!</title>
		<link>http://huddledmasses.org/convert-twitter-users-into-friendfeed-imaginary-friends/</link>
		<comments>http://huddledmasses.org/convert-twitter-users-into-friendfeed-imaginary-friends/#comments</comments>
		<pubDate>Sat, 16 May 2009 20:15:47 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Application programming interface]]></category>
		<category><![CDATA[Automation]]></category>
		<category><![CDATA[FriendFeed]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[WatiN]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://joelbennett.net/?p=1170</guid>
		<description><![CDATA[So a lot of people seem to be taking the latest missteps by Twitter&#8217;s management (and the accompanying admission of bad design) as an opportunity to try out some alternatives. Many of them seem to be coming over to FriendFeed (which has been better than Twitter for a long time, but nevermind that) ... so [...]]]></description>
			<content:encoded><![CDATA[	<p>So a lot of people seem to be taking the <a href="http://blog.twitter.com/2009/05/whoa-feedback.html">latest missteps</a> by Twitter&#8217;s management (and <a href="http://blog.twitter.com/2009/05/replies-kerfuffle.html">the accompanying admission of bad design</a>) as an opportunity to try out some alternatives. Many of them seem to be coming over to FriendFeed (which has been better than Twitter for a long time, but nevermind that) ... so I thought I&#8217;d update and release a PowerShell 2.0 script I wrote to create <a href="http://friendfeed.com/settings/imaginary">imaginary friends</a> out of your friends that stay on Twitter.</p>

	<p>The first part of it is a WatiN script (that automates your browser) called <code>New-ImaginaryFriend</code> which takes three parameters: a name for the imaginary friend, a url for an avatar for the friend, and a HashTable&#8230;  Of course, we sort-of cheat by using the HashTable &#8230; it&#8217;s basically a bunch of key-value pairs of remote services and user names. You can use it to add twitter ID&#8217;s like <code>twitter=&#34;jsnover&#34;</code> or blogs like <code>blog=&#34;http://HuddledMasses.org/&#34;</code> etc.  You can even add multiple sources (eg: twitter + diigo, two blogs, etc) to a single new imaginary friend  <img src='http://huddledmasses.org/wordpress/wp-includes/' alt='8)' class='wp-smiley' /> ...</p>

	<p>This script is done using WatiN because the FriendFeed <span class="caps">API</span> doesn&#8217;t support creating imaginary friends yet, and as a result it&#8217;s slow, and requires IE (and doesn&#8217;t seem to work very well with IE8 &#8212; at least, I couldn&#8217;t get it to set the avatars using IE 8 on Windows 7, so I commented out the avatar part of the next-to-last line).</p>

	<p>The other part of the script is a pair of functions: the first is <code>Get-FriendFeedFriends</code> which retrieves profile information for all your friends in a slick format that includes all their services and such &#8230; you may find other uses for this later  <img src='http://huddledmasses.org/wordpress/wp-includes/' alt=';-)' class='wp-smiley' /> , the second is <code>Get-TwitterFriends</code> &#8230; Both have an <code>-Exclude</code> parameter so you can pass it a list of people to ignore.</p>

	<p>When you put these three functions together, you can just import the FriendFeed module, and start creating friends (don&#8217;t forget <em>this</em> version of the scripts only works with IE6 or IE7 for the purpose of avatars, as WatiN can&#8217;t seem to set the file upload value in IE8 yet).</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #0066cc; font-style: italic;">Import-<span style="font-style: normal;">Module</span></span> FriendFeed<br />
<span style="color: #666666; font-style: italic;">## Get any twitter friends who aren't on friendfeed</span><br />
<span style="color: #666666; font-style: italic;">## Make sure you use FriendFeed's built in &quot;add all your twitter friends&quot; first</span><br />
<span style="color: #660033; font-weight: bold;">$twits</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">TwitterFriends</span></span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">-Nickname</span> jaykul<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">-Exclude</span> $<span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">FriendFeedFriends</span></span> jaykul <span style="color: #66cc66;">|</span> <span style="color: #660033;">select</span> <span style="color: #000066;">-expand</span> twitter<span style="color: #333;">&#41;</span><br />
<br />
<span style="color: #666666; font-style: italic;">## Add them to friend feed</span><br />
<span style="color: #666699; font-weight: bold;">foreach</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$twit</span> <span style="color: #666699; font-weight: bold;">in</span> <span style="color: #660033; font-weight: bold;">$twits</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">ImaginaryFriend</span></span> <span style="color: #660033; font-weight: bold;">$twit</span>.<span style="color: #003366;">name</span> @<span style="color: #333;">&#123;</span>twitter<span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$twit</span>.<span style="color: #003366;">screen_name</span><span style="color: #333;">&#125;</span> <span style="color: #660033; font-weight: bold;">$twit</span>.<span style="color: #003366;">profile_image_url</span><br />
<span style="color: #333;">&#125;</span></div>

	<p>You can <a href="/downloads/FriendFeedModule+Dependencies.zip">download all of the required modules at once</a> (<a href="/downloads/FriendFeedModule+Dependencies.7z">7z</a>), or grab the latest versions of them from PoshCode: <a href="http://poshcode.org/1110">FriendFeed</a>, <a href="http://poshcode.org/1107">HttpRest</a>, and  <a href="http://poshcode.org/1108">WatiN</a> &#8230; but if you do that, you&#8217;ll still need to get the binaries separately  <img src='http://huddledmasses.org/wordpress/wp-includes/' alt=':-/' class='wp-smiley' /> </p>

<div class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/2f4a4fcd-2d3b-4c5e-b812-d1c5f2b5624b/" title="Reblog this post [with Zemanta]"><img class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=2f4a4fcd-2d3b-4c5e-b812-d1c5f2b5624b" alt="Reblog this post [with Zemanta]" /></a><span class="zem-script more-related pretty-attribution"><script type="text/javascript" src="http://static.zemanta.com/readside/loader.js" defer="defer"></script></span></div>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/convert-twitter-users-into-friendfeed-imaginary-friends/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using PowerShell and WatiN (PowerWatin?)</title>
		<link>http://huddledmasses.org/using-powershell-and-watin-powerwatin/</link>
		<comments>http://huddledmasses.org/using-powershell-and-watin-powerwatin/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 06:10:50 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Automation]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[WatiN]]></category>
		<category><![CDATA[WebDesign]]></category>
		<category><![CDATA[WebDevelopment]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1111</guid>
		<description><![CDATA[This is an update to a previous article. Someone asked (on Twitter) about using WatiN from PowerShell, and pointed to this old post by Scott Hanselman saying he was having the same problems &#8230; so I wrote this to help them out: WatiN requires -STA mode Note: WatiN requires Single Threaded Apartment mode, so you [...]]]></description>
			<content:encoded><![CDATA[	<h2>This is an update to a previous article.</h2>

	<p>Someone asked (on Twitter) about using <a href="http://watin.sourceforge.net">WatiN</a> from PowerShell, and pointed to <a href="http://www.hanselman.com/blog/WATIRForNETWatiNApproaches08ReleaseAndAutomatingIEFromPowerShell.aspx">this old post by Scott Hanselman</a> saying he was having the same problems &#8230; so I wrote this to help them out:</p>

	<h5>WatiN requires -<span class="caps">STA</span> mode</h5>

	<p>Note: WatiN requires Single Threaded Apartment mode, so you need to be using PowerShell 2.0 (currently in CTP3) in order for any of this to work, and you need to pass the -<span class="caps">STA</span> parameter to PowerShell. Regardless, I thought I&#8217;d throw two tips out here:</p>

	<h3>Don&#8217;t use <code>LoadFile</code>, use <code>LoadFrom</code></h3>

	<p>I&#8217;m not 100% sure when it&#8217;s appropriate to use <strong>LoadFile</strong> in PowerShell, but I can tell you that if your assembly is in a folder with a bunch of other assemblies upon which it depends &#8230; you need to use <code>[Reflection.Assembly]::LoadFrom( $path )</code> instead &#8212; because the .net loader will be able to find the dependencies.</p>

	<h3>Generate some functions to help yourself out</h3>

	<p>It&#8217;s trivial to do code-generation in PowerShell, and WatiN is not friendly to the PowerShell syntax, so you&#8217;re going to want to generate a bunch of them.  To get you started, here&#8217;s a set of Find-* functions to let you find each type of element that WatiN recognizes and automates&#8230; by name, id, class, style &#8230; well, by any attribute, really:</p>

<span id="more-1111"></span>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666699; font-weight: bold;">Function</span> <span style="color: #0066cc; font-style: italic;">Start-<span style="font-style: normal;">Watin</span></span> <span style="color: #333;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">## CHANGE this to point to your WatiN.Core.dll</span><br />
<span style="color: #660033; font-weight: bold;">$WatinPath</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">Convert-<span style="font-style: normal;">Path</span></span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Resolve-<span style="font-style: normal;">Path</span></span> <span style="color: #009900;">&quot;$(Split-Path $Profile)\Libraries\WatiN.Core.dll&quot;</span><span style="color: #333;">&#41;</span><br />
<span style="color: #666666; font-style: italic;">## Load the assembly</span><br />
<span style="color: #660033; font-weight: bold;">$global</span>:watin <span style="color: #66cc66;">=</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>Reflection.<span style="color: #003366;">Assembly</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">LoadFrom</span><span style="color: #333;">&#40;</span> <span style="color: #660033; font-weight: bold;">$WatinPath</span> <span style="color: #333;">&#41;</span><br />
<span style="color: #666666; font-style: italic;">## Create an initial window (I'm creating IE, but WatiN handles Firefox too)</span><br />
<span style="color: #660033; font-weight: bold;">$global</span>:ie <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">new-<span style="font-style: normal;">object</span></span> WatiN.<span style="color: #003366;">Core</span>.<span style="color: #003366;">IE</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;http://www.google.com&quot;</span><span style="color: #333;">&#41;</span><br />
<span style="color: #666666; font-style: italic;">## Generate Find-Button, Find-TextField, etc:</span><br />
<span style="color: #660033; font-weight: bold;">$ie</span> <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Member</span></span> <span style="color: #000066;">-Type</span> Method <span style="color: #66cc66;">|</span> <br />
&nbsp; &nbsp; &nbsp; Where<span style="color: #66cc66;">-</span>Object <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$type</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">Definition</span>.<span style="color: #333399; font-weight: bold; font-style: italic;">Split</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot; &quot;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>WatiN.<span style="color: #003366;">Core</span>.<span style="color: #003366;">Element</span><span style="color: #333;">&#93;</span></span>.<span style="color: #003366;">IsAssignableFrom</span><span style="color: #333;">&#40;</span> <span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">type</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$type</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span> <span style="color: #66cc66;">|</span> ForEach<span style="color: #66cc66;">-</span>Object <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Item</span></span> <span style="color: #000066;">-Path</span> <span style="color: #009900;">&quot;Function:Find-$($_.Name)&quot;</span> <span style="color: #000066;">-Value</span> $<span style="color: #333;">&#40;</span> <span style="color: #660033;">iex</span> @<span style="color: #009900;">&quot;<br />
{<br />
Param(<span style="color: #000099; font-weight: bold;">`$</span>Attribute, [regex]<span style="color: #000099; font-weight: bold;">`$</span>value)<br />
<span style="color: #000099; font-weight: bold;">`$</span>ie.$($_.Name)( ([Watin.Core.Find]::By( <span style="color: #000099; font-weight: bold;">`$</span>Attribute, <span style="color: #000099; font-weight: bold;">`$</span>value)) )<br />
}<br />
&quot;</span>@ &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span></div>

	<p>With just that little bit of code, I generated all of these functions:</p>

	<ul>
		<li>Find-Area</li>
		<li>Find-Button</li>
		<li>Find-CheckBox</li>
		<li>Find-Div</li>
		<li>Find-Element</li>
		<li>Find-FileUpload</li>
		<li>Find-Form</li>
		<li>Find-Image</li>
		<li>Find-Label</li>
		<li>Find-Link</li>
		<li>Find-Para</li>
		<li>Find-RadioButton</li>
		<li>Find-SelectList</li>
		<li>Find-Span</li>
		<li>Find-Table</li>
		<li>Find-TableBody</li>
		<li>Find-TableCell</li>
		<li>Find-TableRow</li>
	</ul>
	<ul>
		<li>Find-TextField</li>
	</ul>

	<p>And each function takes the name of an attribute, like say: Alt, Class, For, Id, Index, Name, Src, Style, Text, Title, Url, Value &#8230; or just &#8220;Element&#8221; ... and a regular expression to match against the value of that attribute, and finds the control(s) that match.  So for instance &#8230; since I&#8217;ve got a browser open to Google, I could trigger a search for my name by just doing:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #0066cc; font-style: italic;">Find-<span style="font-style: normal;">TextField</span></span> Name q <span style="color: #66cc66;">|</span> <span style="color: #66cc66;">%</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">TypeText</span><span style="color: #333;">&#40;</span> <span style="color: #009900;">&quot;Joel Bennett&quot;</span> <span style="color: #333;">&#41;</span> <span style="color: #333;">&#125;</span><br />
<span style="color: #0066cc; font-style: italic;">Find-<span style="font-style: normal;">Button</span></span> Name btnG <span style="color: #66cc66;">|</span> <span style="color: #66cc66;">%</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">Click</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>Drat, the lawyer and that pottery guy still beat me out, maybe I should stop using &#8220;Jaykul&#8221; everywhere and start using my real name more &#8230;</p>

	<h2> <img src='http://huddledmasses.org/wordpress/wp-includes/' alt='[new]' class='wp-smiley' />  <em>Edit</em>: Another example</h2>

	<p>Someone asked in the comments about how to parse a table, and I thought I&#8217;d post an example, because it&#8217;s pretty cool how well PowerShell works for stuff like this.  Lets say I wanted to scan down a column in a table, and depending on the values, return a value from another column. For an example, I&#8217;ll take a table off Wikipedia which lists multi-protocol IM clients, and try to return the names of the clients which support <span class="caps">IRC</span>.</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666666; font-style: italic;">## Using the function defined earlier ...</span><br />
<span style="color: #0066cc; font-style: italic;">Start-<span style="font-style: normal;">Watin</span></span><br />
<span style="color: #666666; font-style: italic;">## Now navigate to the page</span><br />
<span style="color: #660033; font-weight: bold;">$ie</span>.<span style="color: #003366;">Goto</span><span style="color: #333;">&#40;</span> <span style="color: #009900;">&quot;http://en.wikipedia.org/wiki/Multiprotocol_instant_messaging_application&quot;</span> <span style="color: #333;">&#41;</span><br />
<span style="color: #666666; font-style: italic;">## Find that first table (yeah, you just have to know the ID):</span><br />
<span style="color: #660033; font-weight: bold;">$table</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">Find-<span style="font-style: normal;">Table</span></span> Id sortable_table_id_0<br />
<br />
<span style="color: #666666; font-style: italic;">## we COULD do this to figure out which column is the IRC column:</span><br />
<span style="color: #666666; font-style: italic;">## It's hard because there's no mapping for TH in WatiN</span><br />
<span style="color: #666666; font-style: italic;">## Personally, I think they should show up in .TableCells</span><br />
<span style="color: #666666; font-style: italic;">## -1 for the &quot;th&quot; element that's missing from TableRow[1..n].TableCells</span><br />
<span style="color: #660033; font-weight: bold;">$column</span><span style="color: #66cc66;">=-</span><span style="color: #cc66cc;">1</span>; <br />
<span style="color: #660033; font-weight: bold;">$table</span>.<span style="color: #003366;">TableRows</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Elements</span> <span style="color: #66cc66;">|</span> Where<span style="color: #66cc66;">-</span>Object <span style="color: #333;">&#123;</span><span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">TagName</span> <span style="color: #000066;">-eq</span> <span style="color: #009900;">&quot;th&quot;</span><span style="color: #333;">&#125;</span> <span style="color: #66cc66;">|</span> <br />
&nbsp; &nbsp;ForEach<span style="color: #66cc66;">-</span>Object<span style="color: #333;">&#123;</span> <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">Text</span> <span style="color: #000066;">-match</span> <span style="color: #009900;">&quot;IRC&quot;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#123;</span> <span style="color: #666699; font-weight: bold;">break</span> <span style="color: #333;">&#125;</span> <span style="color: #660033; font-weight: bold;">$column</span><span style="color: #66cc66;">++</span> <span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">## Now we loop all rows, and examine that column </span><br />
<span style="color: #666666; font-style: italic;">## If we find a &quot;Yes&quot;, print out the table header for that row:</span><br />
<span style="color: #660033; font-weight: bold;">$table</span>.<span style="color: #003366;">TableRows</span> <span style="color: #66cc66;">|</span> Where<span style="color: #66cc66;">-</span>Object <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">TableCells</span><span style="color: #333;">&#91;</span><span style="color: #660033; font-weight: bold;">$column</span><span style="color: #333;">&#93;</span> <span style="color: #000066;">-match</span> <span style="color: #009900;">&quot;Yes&quot;</span> <span style="color: #333;">&#125;</span> <span style="color: #66cc66;">|</span> <br />
&nbsp; &nbsp;ForEach<span style="color: #66cc66;">-</span>Object <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">Elements</span> <span style="color: #333;">&#125;</span> <span style="color: #66cc66;">|</span> <br />
&nbsp; &nbsp;Where<span style="color: #66cc66;">-</span>Object &nbsp; <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">TagName</span> <span style="color: #000066;">-eq</span> <span style="color: #009900;">&quot;th&quot;</span><span style="color: #333;">&#125;</span> <span style="color: #66cc66;">|</span> <br />
&nbsp; &nbsp;ForEach<span style="color: #66cc66;">-</span>Object <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">Text</span> <span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>Clearly WatiN needs to fix the missin <code>&#60;th&#62;</code> TableHeader problem, but other than that, this wasn&#8217;t too painful. Of course, it would be a lot easier if we could cast ScriptBlocks as the generic <code>Predicate&#60;T&#62;</code> that the various .Find methods accept, but if I try this, it just freezes up and never returns:</p>

	<div class="posh code posh" style="font-family:monospace;"><span style="color: #660033; font-weight: bold;">$table</span>.<span style="color: #003366;">TableRows</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Element</span><span style="color: #333;">&#40;</span> <span style="color: #333;">&#123;</span><span style="color: #660033; font-weight: bold;">$arg</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">TagName</span> <span style="color: #000066;">-eq</span> <span style="color: #009900;">&quot;th&quot;</span><span style="color: #333;">&#125;</span> <span style="color: #333;">&#41;</span></div>

	<h3>Future Work</h3>

	<p>You could easily take this a lot further: dump those functions into a file for reusing next time (so you don&#8217;t have to regenerate them each time), and in fact, it would be relatively simple to make functions for each of the methods on each of the types we found above, so you would have a <code>Click-Button</code> function, and a <code>TypeText-TextField</code> function which could take those same search parameters (attribute and regular expression) and you could even generate appropriate parameters to take, for example, the text to type.  In fact, you could generate a whole <span class="caps">DSL</span> for yourself &#8230; <a href="http://www.codinginstinct.com/2008/11/browser-automation-dsl-using-mgrammar.html">this guy did it using MGrammar</a> &#8230; but why not PowerShell.  <img src='http://huddledmasses.org/wordpress/wp-includes/' alt=';)' class='wp-smiley' /> </p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/using-powershell-and-watin-powerwatin/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

