just_add_watir | Advanced recipes for Watir
21Aug/08Off

Q. How do I attach to a current IE session?

A. Use the .attach method...
Example watir:

@b=Watir::IE.attach(:title,//)

I have used regex here for the window title, you can be more specific if you like.

Tagged as: , 1 Comment
14Aug/08Off

Q. How do I set a checkbox with a dynamic id attribute?

A. Use a regex match to populate a dynamic variable ...
Example html:

<form action="test_0019.html" method="get" accept-charset="utf-8">
<input id="cblRoles_3" type="checkbox" tabindex="47" name="cblRoles:3"/>
<label for="cblRoles_3">Customer</label>
<input id="cblRoles_4" type="checkbox" tabindex="48" name="cblRoles:4"/>
<label for="cblRoles_4">Expedite</label>

Example watir:

dynamic_id = @b.html[/cblRoles_\d+>Expedite/].gsub(">Expedite","")
@b.checkbox(:id,dynamic_id).set