QTP/UFT beginner tutorial: Recognizing an object that has special characters within it’s property values

Test Button & @*[9]

Hi! Today, I am going to show you how to recognize an object that has special characters within it's property values. Take a look at the object above. It uses special characters in it's property values. QTP/UFT takes these characters and recognizes them as regular expressions. Because of this, QTP/UFT will become confused and will not find the object if you simply use a unique property value. 

1. I spied  the object with the object spy tool, and  I found that the object name is name:=Test Button & @*[9]

If you use the name value directly from the spy object, your code will fail. I set up the code below to test if the object is found by QTP/UFT. If the object is found, I will receive a "Pass" message.

If Browser("name:=QTP/UFT beginner tutorial: Recognizing an object that has special characters within it’s property values \|").Page("title:=QTP/UFT beginner tutorial: Recognizing an object that has special characters within it’s property values \|").Link("outertext:=Test Button & @*[9]").Exist Then
    MsgBox "Pass"
End If 

As you see, the code above does not find the object that we're looking for.

2. Instead of just copying the property name value directlu from the object spy, click the copy to clipboard icon in the object spy. Then just perform the paste command in a notepad.

This will copy all the object property values in a way that converts the special characters to a regular string format.

You can see that QTP/UFT took the special characters in the objects, and placed the \ before them. This tells QTP/UFT that every special character with a \ in front of it, should be treated as a regular string.

3. Copy this line of code and insert this in your object description without the comma at the end.

If Browser("name:=QTP/UFT beginner tutorial: Recognizing an object that has special characters within it’s property values \|").Page("title:=QTP/UFT beginner tutorial: Recognizing an object that has special characters within it’s property values \|").Link("name:=Test Button & @\*\[9\]").Exist Then
MsgBox "Pass"
End If 

Your object will now be recognized and QTP/UFT will send you the message "Pass". This example can also be seen in our QTPtutorial.net Page name and the Page title where the | special character is used. Use the copy to clipboard QTP/UFT functionality for all of your object identification needs and you can't go wrong! You can also do this yourself manually by adding a backslash \ before any special character.  If you have any questions, paste a comment below. If you have a request for a tutorial, paste a comment below!

 

Pin It on Pinterest

Clef two-factor authentication