Aug
21
2008
0

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.

Written by Sameh Abdelhamid in: watir | Tags: ,
Aug
14
2008
0

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
Written by Tim Koopmans in: watir | Tags: , , ,
Jul
24
2008
0

Q. What’s with the /i in Ruby regular expressions?

A. the /i indicates an ignore case modifier …
In Ruby, a regular expression is written in the form of /pattern/modifiers where “pattern” is the regular expression itself, and “modifiers” are a series of characters indicating various options.
Ruby supports the following modifiers:
* /i makes the regex match case insensitive.
* /m makes the dot match newlines. Ruby indeed uses /m, whereas Perl and
many other programming languages use /s for “dot matches newlines”.
* /x tells Ruby to ignore whitespace between regex tokens.
* /o causes any #{…} substitutions in a particular regex literal to be performed just once, the first time it is evaluated. Otherwise, the substitutions will be performed every time the literal generates a Regexp object.
You can combine multiple modifiers by stringing them together as in /regex/is.
See more information here: http://www.regular-expressions.info/ruby.html

Written by Tim Koopmans in: watir | Tags:
Jul
17
2008
0

Q. How do I get text from a browser?

A. Use a regex match on the .text method …
Example html:

<p>
  The Employee Code assigned is 10000671
</p>

Example watir:

puts /(1\d+)/.match(@b.text)
Written by Sameh Abdelhamid in: watir | Tags: ,
Jul
17
2008
0

Q. How do I check if text exists in browser?

A. Use the .include? method or a regular expression …
Example html:

<p>
  watir does not go well with furry little animals
</p>

Example watir:

puts "Text 'watir' DOES exist" if @b.text.include? 'watir'
puts "Text 'regex' DOES NOT exist" unless @b.text =~ /regex/
puts "Text 'furry little animals' DOES exist" if @b.text.include? 'furry little animals'
puts "Text 'furry animals' DOES NOT exist" unless @b.text.include? 'furry animals'

Any character(s) placed between the apostrophe’s will be searched for. The response will return true if found, and false if not found.

Written by Sameh Abdelhamid in: watir | Tags: , ,

Powered by WordPress | Aeros Theme | TheBuckmaker.com WordPress Themes