<?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>just_add_watir &#124; Advanced recipes for Watir &#187; .gsub</title>
	<atom:link href="http://justaddwatir.com/tag/gsub/feed/" rel="self" type="application/rss+xml" />
	<link>http://justaddwatir.com</link>
	<description>Advanced recipes for Watir</description>
	<lastBuildDate>Wed, 21 Oct 2009 02:44:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Q. How do I set a checkbox with a dynamic id attribute?</title>
		<link>http://justaddwatir.com/2008/q-how-do-i-set-a-checkbox-with-a-dynamic-id-attribute/</link>
		<comments>http://justaddwatir.com/2008/q-how-do-i-set-a-checkbox-with-a-dynamic-id-attribute/#comments</comments>
		<pubDate>Fri, 15 Aug 2008 03:59:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[watir]]></category>
		<category><![CDATA[.checkbox]]></category>
		<category><![CDATA[.gsub]]></category>
		<category><![CDATA[.html]]></category>
		<category><![CDATA[regex]]></category>

		<guid isPermaLink="false">http://justaddwatir.com/watir/?p=40</guid>
		<description><![CDATA[A. Use a regex match  to populate a dynamic variable ...
Example html:

&#60;form action=&#34;test_0019.html&#34; method=&#34;get&#34; accept-charset=&#34;utf-8&#34;&#62;
&#60;input id=&#34;cblRoles_3&#34; type=&#34;checkbox&#34; tabindex=&#34;47&#34; name=&#34;cblRoles:3&#34;/&#62;
&#60;label for=&#34;cblRoles_3&#34;&#62;Customer&#60;/label&#62;
&#60;input id=&#34;cblRoles_4&#34; type=&#34;checkbox&#34; tabindex=&#34;48&#34; name=&#34;cblRoles:4&#34;/&#62;
&#60;label for=&#34;cblRoles_4&#34;&#62;Expedite&#60;/label&#62;

Example watir:

dynamic_id = @b.html&#91;/cblRoles_\d+&#62;Expedite/&#93;.gsub&#40;&#34;&#62;Expedite&#34;,&#34;&#34;&#41;
@b.checkbox&#40;:id,dynamic_id&#41;.set

]]></description>
			<content:encoded><![CDATA[<p><strong>A. Use a regex match  to populate a dynamic variable ...</strong><br />
<a href="http://justaddwatir.com/watir/test_html/tc_0001_0100/test_0019.html">Example html</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;test_0019.html&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;get&quot;</span> <span style="color: #000066;">accept-charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cblRoles_3&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;checkbox&quot;</span> <span style="color: #000066;">tabindex</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;47&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cblRoles:3&quot;</span><span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cblRoles_3&quot;</span>&gt;</span>Customer<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cblRoles_4&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;checkbox&quot;</span> <span style="color: #000066;">tabindex</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;48&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cblRoles:4&quot;</span><span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cblRoles_4&quot;</span>&gt;</span>Expedite<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span></pre></div></div>

<p>Example watir:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dynamic_id = <span style="color:#0066ff; font-weight:bold;">@b</span>.<span style="color:#9900CC;">html</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">/</span>cblRoles_\d<span style="color:#006600; font-weight:bold;">+&gt;</span>Expedite<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#CC0066; font-weight:bold;">gsub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;&gt;Expedite&quot;</span>,<span style="color:#996600;">&quot;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#0066ff; font-weight:bold;">@b</span>.<span style="color:#9900CC;">checkbox</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:id</span>,dynamic_id<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">set</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://justaddwatir.com/2008/q-how-do-i-set-a-checkbox-with-a-dynamic-id-attribute/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
