Regular Expressions
Watir supports regular expressions in method calls.Here is an example using the link method to click a link using the url attribute:
ie.link(:url, /shtml/).click
How do I use regular expressions for object recognition?
Watir allows the tester to use Regular Expressions for object recognition instead of using the full string literal. This is useful for HTML objects that are dynamically created.For example in my WebSphere application we may have a link with this URL
$ie.link(:url, "javascript:PC_7_0_G7_selectTerritory('0',%20'amend')").click
With RegEx we could find that link by doing :
$ie.link(:url, /selectTerritory\('0',%20'amend'\)/).click
$ie.link(:url, /javascript.*selectTerritory\('0',%20'amend'\)/).click
RegEx contains special characters that need to be escaped. For example here ')' we use the backward slash to escape a closing bracket.
To find out what characters need to be escaped, go into irb, then enter
Regexp.escape "javascript:PC_7_0_G7_selectTerritory('0',%20'amend')"
=> "javascript:PC_7_0_G7_selectTerritory\\('0',%20'amend'\\)"
aidy
No comments:
Post a Comment