Sunday 30 August 2015

REGULAR EXPRESSION IN QTP

REGULAR EXPRESSION EXAMPLE

Regular Expressions
A regular expression is a special text string for describing a search for describing a search pattern. You can think of a regular expression as a wild card.You are probably familiar with wild card notations such as *.doc to find all word files in a file manager.


Grouping Regular ExpressionsMultiple Regular Expressions Characters can be combined in a Single Expression. For example :
Window("text:= .*(Report|Graph)").Close
The above line closes a window with Text Report or Graph preceded by any set of alphanumeric characters.

Using  the Backlash Character( \ )
The backlash can be used along with a Regular Expression Character to indicate that the next character be treated as a literal character. ex:-
Browser("Yahoo").Page("Yahoo").Link("text:= .*\..*").Click
Here the backlash is preceded by the .(period) so the .(period) will be considered literal & not a Regular Expression.

Regexp Object
You can use regular expressions in VBScript by creating one or more instances of the RegExp object. This object allows you to find regular expression matches in strings, and replace regexp matches in strings with other strings. You can create this object in scripting as shown below:
Regexp Rx = New Regexp

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.