Wednesday 20 November 2013

How to use regular expression in descriptive programming in QTP?

As we know that there are 2 ways of descriptive programming.

  1. Static
  2. Dynamic
We can use  regular expression in both the ways as mentioned below. Please note that by default all the property values are considered as regular expressions by QTP.


' Regular Expressions in Static descriptive programming in QTP.

Browser("index:=0").page("title:=Google").Webedit("name:=q").set "sagar salunke"
Browser("creationtime:=0").page("title:=Google").Webbutton("name:=Google.*").Click

Please note that last statement uses regular expression to identify the button whose name starts with Google.
If your property value itself contains the special character then that should be escaped using \ character.

Example - Suppose you want to click on the link "+sagar".
Now this link contains the special character +. To click on this link, we can use below code
Browser("creationtime:=0").page("title:=Google").Link("innertext:=\+sagar").Click


' Regular Expressions in Dynamic descriptive programming in QTP.

Set descriptionObject = Description.Create()
descriptionObject("innertext").value = "+sgaar"
descriptionObject("innertext").RegularExpression = false

'Please note that we can specify whether the value is regular expression or not using RegularExpression property. By default it is true.

Browser("index:=0").page("title:=Google").Link(descriptionObject ).click

This is how we can use Regular Expressions in QTP

You may also like below topics on regular expressions in QTP.
  1. Regular Expressions in OR in QTP.
  2. Regular Expressions in descriptive programming in QTP.
  3. Regular expression evaluator in QTP.
  4. Meta characters in regular expressions.
  5. Case insensitive regular expressions in QTP.
  6. Regexp object in QTP.
  7. Global Property in Regular Expressions
Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.

No comments:

Post a Comment

Please Leave your reply. We value your feedback and inputs

Best QTP Books

Everything About QTP

Hello Friends,
You can find QTP study material, Multiple choice questions (mcq), QTP question bank, QTP question papers, QTP notes, QTP questionnaire, scenario based QTP interview questions, QTP tutorial and QTP training on this site.

If you are a fresher or experienced QTP professional with (1/2/3/4) years of experience, this blog is just for you.