Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to disable regular expressions in a text?
#1
Solved: 11 Years, 3 Months, 3 Weeks ago
Hello.
I define an object with the next property and value:
Code:
"innertext:=jfjfjfj*.(fff)"
The problem is that if i do an "exist statement", QTP can not find the object because in the value, it recognizes regular expressions.
What i tried is placing a backslash before all special characters but this is a lot of work. Is there another way i can prefent QTP to find the regular expressions? I want that QTP sees the value as only text, how can i do that?
Reply
#2
Solved: 11 Years, 3 Months, 3 Weeks ago
Hi,
Please use the below function. It receives a normal string and returns the equivalent string in regular expression
Code:
Function NormalizeString(OrgStr)
       Dim TempStr
       TempStr = Replace(OrgStr, "\", "\\")
       TempStr = Replace(TempStr, "*", "\*")
       TempStr = Replace(TempStr, "+", "\+")
       TempStr = Replace(TempStr, ".", "\.")
       NormalizeString = Replace(TempStr, "?", "\?")
End function
Msgbox NormalizeString ("a+b*c.d?e")
Reply
#3
Solved: 11 Years, 3 Months, 3 Weeks ago
Hello Ravi,
Thank you for your answer but i do not get it worked.
What i did, is adding the next line to your function:
TempStr = Replace(TempStr, "$", "\$")
I did this because the $-sign is also a character wich is used as a regular expression, which can cause my problem, i think...?

Then i started this in QTP:
Code:
Function NormalizeString(OrgStr)
       Dim TempStr
       TempStr = Replace(OrgStr, "\", "\\")
       TempStr = Replace(TempStr, "*", "\*")
       TempStr = Replace(TempStr, "+", "\+")
       TempStr = Replace(TempStr, ".", "\.")
       TempStr = Replace(TempStr, "$", "\$")
       NormalizeString = Replace(TempStr, "?", "\?")
End function
Print NormalizeString ("DEPART Frankfurt to Acapulco3/27/2013SELECTFLIGHTDEPARTSTOPS Blue Skies Airlines 360 5:03non-stopPrice: $270 (based on round trip) Blue Skies Airlines 3617:10non-stopPrice: $271 (based on round trip) Pangaea Airlines 3629:17non-stopPrice: $274 (based on round trip) Unified Airlines 36311:24non-stopPrice: $281 (based on round trip)")
In the Print pop-up screen i get this string:
DEPART Frankfurt to Acapulco3/27/2013SELECTFLIGHTDEPARTSTOPS Blue Skies Airlines 360 5:03non-stopPrice: \$270 (based on round trip) Blue Skies Airlines 3617:10non-stopPrice: \$271 (based on round trip) Pangaea Airlines 3629:17non-stopPrice: \$274 (based on round trip) Unified Airlines 36311:24non-stopPrice: \$281 (based on round trip)

Ik put this string into this code:
Code:
If Browser("Welcome: Mercury Tours").Page("Select a Flight: Mercury").WebTable("html tag:=TABLE", "Index:=8", "column names:=DEPART Frankfurt to Acapulco.*","innertext:=DEPART Frankfurt to Acapulco3/27/2013SELECTFLIGHTDEPARTSTOPS Blue Skies Airlines 360 5:03non-stopPrice: \$270 (based on round trip) Blue Skies Airlines 3617:10non-stopPrice: \$271 (based on round trip) Pangaea Airlines 3629:17non-stopPrice: \$274 (based on round trip) Unified Airlines 36311:24non-stopPrice: \$281 (based on round trip)").Exist(1) Then
Reporter.ReportEvent micPass, "OK",""
Else
Reporter.ReportEvent micFail, "NOK",""
End If
Then i got "NOK".

When i remove the innnertext object property i get an "OK".

When i use GetROProperty to get the innertext value it is exactly like i did use it, but why do i get no match?

Whats wrong in?
DEPART Frankfurt to Acapulco3/27/2013SELECTFLIGHTDEPARTSTOPS Blue Skies Airlines 360 5:03non-stopPrice: \$270 (based on round trip) Blue Skies Airlines 3617:10non-stopPrice: \$271 (based on round trip) Pangaea Airlines 3629:17non-stopPrice: \$274 (based on round trip) Unified Airlines 36311:24non-stopPrice: \$281 (based on round trip)
Reply
#4
Solved: 11 Years, 3 Months, 3 Weeks ago
There could be other elements with same innertext.It would easy identifying the root cause if you could post the source code.
Reply
#5
Solved: 11 Years, 3 Months, 3 Weeks ago
This is my code:
Code:
If FlightFinderPag.WebTable("html tag:=TABLE", "Index:=8", "column names:=DEPART Frankfurt to Acapulco.*","innertext:=DEPART Frankfurt to Acapulco3/1/2013SELECTFLIGHTDEPARTSTOPS Blue Skies Airlines 360 5:03non-stopPrice: \$270 (based on round trip) Blue Skies Airlines 3617:10non-stopPrice: \$271 (based on round trip) Pangaea Airlines 3629:17non-stopPrice: \$274 (based on round trip) Unified Airlines 36311:24non-stopPrice: \$281 (based on round trip)").Exist(1) Then
Reporter.ReportEvent micPass, "OK",""
Else
Reporter.ReportEvent micFail, "NOK,""
End If
----------------------------------------------------------------------
I investigated the WebTable an see that the same textvalue is also in the "outertext" property, can this be a problem? When i run my QTP script without the "innertext" i got an "OK" message.
Reply
#6
Solved: 11 Years, 3 Months, 3 Weeks ago
Yess after applying the last post, it works now.
Thanks all!
Reply
#7
Solved: 11 Years, 3 Months, 3 Weeks ago
Please ensure to include your code between [code] tags while asking or replying to questions. I have done this for you for this time.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
At Regular Expressions for e-mail address ganesh.dengale 6 19,153 08-23-2022, 02:51 PM
Last Post: ahmad3029
  Need help on using regular expressions on Java Window's title qa_tester 3 5,049 02-13-2012, 10:56 PM
Last Post: madsenfr
  java window titles & regular expressions jotdog2 1 4,211 02-13-2012, 10:55 PM
Last Post: madsenfr
  Process to use Regular Expressions in QTP using screen shots. yvslraotesting@gmail.com 1 3,495 01-31-2012, 12:45 PM
Last Post: basanth27
  Run error: Object is disable bea 5 11,651 01-11-2012, 12:45 AM
Last Post: sunnyk8

Forum Jump:


Users browsing this thread: 1 Guest(s)