Interview Questions   Tutorials   Discussions   Programs   Videos   

QTP - How to use Regular Expressions in QTP? give an example.

asked marvit August 13, 2014 04:51 AM  

How to use Regular Expressions in QTP? give an example.


2 Answers

answered By Dharma   0  
Regular Expression

   add comment

answered By Dharma   0  

Steps to Use Regular Expression in QTP
1.  Go to Object Repository. Navigation: Resources>>Object Repository.

2.  Select the Object which you want to specify regular expression.

3.  In the right side you can observe properties of that object.

4.  Select the property which you want to specify regular expression.

5.  Click on the property value of that property and the property value is editable. There is a configure button appeared with the
     symbol ”<#>”

6.  Click on the configure button or use Ctrl+F11 to open configure window.

7.  Select Regular Expression check box.

 a.  If the property value is having any special characters then QTP will display a dialog with asking
      Do you want to add the backslash (\) before each special character in order to treat it literally?

 b.  If you click on yes QTP will automatically gives the backslash before every special character. So that the special
      characters will be treated as literal.

8.  Now specify the regular expression in constant edit box.

9.  Click on OK.

10. Observe that a symbol “A.*” is added in property field. This means, that property is using regular expression.

11. Highlight the object in application to ensure that the provided regular expression is working fine.


While specifying properties we can give regular expressions. By default the properties will be treated as regular expression when you added to description object.
Set oDescription=Description.Create
oDescription("micclass").value= "Browser"
oDescription("openurl").value= ""

Here in this URL property there are three dots (.) which can be treated as regular expressions. These dots will work as regular expressions because by default the property values will be treated as regular expressions.

There is a property called regularexpression for description object which is used to set the property values to work as regular expressions or as a literal string values.

In the Above example, set the regularexpression property to false to treat "" as a literal string.

Set oDescription=Description.Create
oDescription("micclass").value= "Browser"
oDescription("openurl").value= ""
oDescription("openurl").regularexpression = False

oDescription("openurl").regularexpression = False 

   add comment

Your answer

Join with account you already have



Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!