Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ho to get a part of innertext's value
#1
Solved: 11 Years, 4 Months, 4 Weeks ago Question 
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.
Reply
#2
Solved: 11 Years, 4 Months, 4 Weeks ago
Hi
try below code:

Code:
InnerTextValue ="Search Results (4)"

TextValue=split(InnerTextValue,"(")

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


~Regards
Reply
#3
Solved: 11 Years, 4 Months, 4 Weeks ago
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
Reply
#4
Solved: 11 Years, 4 Months, 4 Weeks ago
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
Reply
#5
Solved: 11 Years, 4 Months, 4 Weeks ago
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
Reply
#6
Solved: 11 Years, 4 Months, 4 Weeks ago
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
Reply
#7
Solved: 11 Years, 4 Months, 4 Weeks ago
Hi supputuri

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

~Regards
Reply
#8
Solved: 11 Years, 4 Months, 4 Weeks ago
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
Reply
#9
Solved: 11 Years, 4 Months, 4 Weeks ago
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
Reply
#10
Solved: 11 Years, 4 Months, 4 Weeks ago
yep thanks, or we can do next:

InnerTextValue ="Search Results (9856742310)"

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

how do you think supputuri?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Part of parameters missing when passing between actions skumar007 1 3,033 10-10-2014, 02:00 AM
Last Post: skumar007
  Webelement innertext is not case sensitive san4hex 7 6,288 05-13-2013, 02:59 PM
Last Post: basanth27
  Parameterizing a part of script itsnotmyid 3 3,534 08-09-2011, 09:02 AM
Last Post: parminderdhiman84
Question Doesn't store value into database using Innertext Langxii 1 2,927 07-05-2011, 07:48 PM
Last Post: rajpes
  Exist returns false with part of innertext Milindt43 1 2,989 02-23-2011, 09:56 PM
Last Post: basanth27

Forum Jump:


Users browsing this thread: 1 Guest(s)