Posts: 47
Threads: 9
Joined: Feb 2010
Reputation:
0
08-18-2010, 05:10 PM
Hi All,
my issue is next:
I have an WebElement which have next innertext for e.g.:
Search Results (4)
can anyone help me to get the number from () and assign it to a variable, because it is always different, and I have to compare it with some other numbers.
I'll have next line:
Code: InnerTextValue = Browser("URL:=" & Environment.Value("baseUrl")).Page("URL:=" & Environment.Value("baseUrl")).WebElement("outertext := Search Results (4)", "html tag := LEGEND").GetROProperty ("innertext")
Now:
InnerTextValue = "Search Results (4)"
I just don't know how to get the '4' from there.
Posts: 36
Threads: 0
Joined: Jul 2010
Reputation:
0
08-18-2010, 06:01 PM
(This post was last modified: 08-18-2010, 06:02 PM by QTPLearn.)
Hi
try below code:
Code: InnerTextValue ="Search Results (4)"
TextValue=split(InnerTextValue,"(")
strReqString= (Mid(TextValue(1),1,1))
msgbox strReqString
~Regards
Posts: 240
Threads: 38
Joined: Jun 2009
Reputation:
0
08-18-2010, 06:24 PM
(This post was last modified: 08-18-2010, 08:09 PM by venkatbatchu.)
Hi,
You could go by this way
Code: Left((Right(InnerTextValue,2)),1)
With this you will get 4 in to the variable.
Please let me know for further clarification.
Regards,
Venkat.Batchu
Posts: 516
Threads: 17
Joined: Jul 2009
Reputation:
3
08-18-2010, 08:20 PM
Hi QTP Learner and Venkatesh,
I appreciate your responses, but what will happen if tomorrow he got (12345XXXX). Then it will break, so we have to make it very generic as below
Code: InnerTextValue ="Search Results (9856742310)"
SearchResults = Split(Split(InnerTextValue,"(")(1),")")(0)
If SearchResults = "" Then
Msgbox "No Search results found."
Else
Msgbox SearchResults
End If
In this way we can reduce the LOC and make it more generic.
Let me know if you have questions or need any more information.
Thanks,
SUpputuri
Posts: 240
Threads: 38
Joined: Jun 2009
Reputation:
0
08-18-2010, 08:55 PM
Hi Supputuri,
by using split we could reduce the code. I have seen 4 and directly wrote the solution for the mentioned issue.I didnt think any other than that value.
Any way thanks alot.
Regards,
Venkat.Batchu
Posts: 47
Threads: 9
Joined: Feb 2010
Reputation:
0
08-19-2010, 05:42 PM
(This post was last modified: 08-19-2010, 05:45 PM by lotos.)
Hi Venkatbtchu, I've mentioned about: 'can anyone help me to get the number from () and assign it to a variable, because it is always different'
Thanks,
Hmmm, interesting, I will try the method and I will inform you about the result..
At the moment I've compared the entire variable with the same second variable:
Code: InnerTextValue1 ="Search Results (xxx)"
InnerTextValue2 ="Search Results (yyy)"
Thanks a lot
Posts: 36
Threads: 0
Joined: Jul 2010
Reputation:
0
08-20-2010, 10:17 AM
Hi supputuri
Thanks for your suggestion. Generic solution is always a good approach.
~Regards
Posts: 47
Threads: 9
Joined: Feb 2010
Reputation:
0
09-16-2010, 06:13 PM
(This post was last modified: 09-16-2010, 06:14 PM by lotos.)
Hi supputuri,
thanks a lot, but I've used 'replace' function here, and it's something like:
Code: InnerTextValue ="Search Results (9856742310)"
LeftInTextVal = replace(InnerTextValue, "Search Results (", "") 'the value will become: 9856742310)
InTextVal = replace(LeftInTextVal, ")", "") ' here the value will become: 9856742310
So at the end I'll have: InTextVal = 9856742310
Posts: 516
Threads: 17
Joined: Jul 2009
Reputation:
3
09-16-2010, 08:15 PM
Hi lotos,
Yeah, absolutly we can follow method what have done.
There are many ways to handle the action, but we have to go with the one which won't kill the memory and easy. So, the solution which I have provided will met both the primary things.
Thanks,
SUpputuri
Posts: 47
Threads: 9
Joined: Feb 2010
Reputation:
0
01-11-2011, 07:46 PM
yep thanks, or we can do next:
InnerTextValue ="Search Results (9856742310)"
Code: InTextVal = replace((replace(InnerTextValue, "Search Results (", "")), ")", "")
how do you think supputuri?
|