Micro Focus QTP (UFT) Forums
ho to get a part of innertext's value - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: ho to get a part of innertext's value (/Thread-ho-to-get-a-part-of-innertext-s-value)



ho to get a part of innertext's value - lotos - 08-18-2010

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.


RE: ho to get a part of innertext's value - QTPLearn - 08-18-2010

Hi
try below code:

Code:
InnerTextValue ="Search Results (4)"

TextValue=split(InnerTextValue,"(")

strReqString= (Mid(TextValue(1),1,1))
msgbox strReqString


~Regards


RE: ho to get a part of innertext's value - venkatbatchu - 08-18-2010

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


RE: ho to get a part of innertext's value - supputuri - 08-18-2010

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.


RE: ho to get a part of innertext's value - venkatbatchu - 08-18-2010

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


RE: ho to get a part of innertext's value - lotos - 08-19-2010

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


RE: ho to get a part of innertext's value - QTPLearn - 08-20-2010

Hi supputuri

Thanks for your suggestion. Generic solution is always a good approach.

~Regards


RE: ho to get a part of innertext's value - lotos - 09-16-2010

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
Wink


RE: ho to get a part of innertext's value - supputuri - 09-16-2010

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.


RE: ho to get a part of innertext's value - lotos - 01-11-2011

yep thanks, or we can do next:

InnerTextValue ="Search Results (9856742310)"

Code:
InTextVal = replace((replace(InnerTextValue, "Search Results (", "")), ")", "")

how do you think supputuri?