Highlighted
Honored Contributor.. Honored Contributor..
Honored Contributor..
7287 views

WebElement: Getting the innertext property dynamically

Jump to solution

Hello,

I'm having a problem with a little piece of code and I don't understand why.

What I'm trying to do is the following: I have a page where I need to calculate the amount of an offer. When we first get to the page, the innertext property of the field is Fr. 0.00. There are several fields to fill out and at the end, we need to click on a button to calculate the amount. It takes a few seconds for the field to be updated and I have a while loop that waits until the innertext property of the field is different from Fr. 0.00

This is part of the code I have. The problem is that it does not detect the change in the innertext property. If I run the code when innertext = "Fr. 0.00", the while loop is correctly executed and if I run it when innertext <> "Fr. 0.00", it does not enter the while loop. But if the innertext property changes while the code is inside the while loop, it does not exit the loop, which is what I want to happen of course. What am I doing wrong?

Thank you.

TEND_ObjectPropertyValue "TEST", Browser("xxx").Page("xxx").WebElement("xxx")"innertext""Fr. 0.00"

Sub TEND_ObjectPropertyValue(transName, testObject, objectProperty, objectPropertyValue)
    
   While UCase(Trim(CStr(testObject.getROProperty(objectProperty)))) = UCase(Trim(CStr(objectPropertyValue)))
       If DateDiff("s", perf_timer_starttime, now) > perf_timer_timeoutsec Then
           ExitTest
       End If
    Wend
    
End Sub

0 Likes
1 Solution

Accepted Solutions
Highlighted
Outstanding Contributor.
Outstanding Contributor.

Re: WebElement: Getting the innertext property dynamically

Jump to solution

Since the Object is refreshed after your first operation, you should use the RefreshObject method as given below.

Sub TEND_ObjectPropertyValue(transName, testObject, objectProperty, objectPropertyValue)
    
   While UCase(Trim(CStr(testObject.getROProperty(objectProperty)))) = UCase(Trim(CStr(objectPropertyValue)))
       If DateDiff("s", perf_timer_starttime, now) > perf_timer_timeoutsec Then
           ExitTest
       End If

       testObject.RefreshObject
    Wend
    
End Sub

Check this article for more details.

_____________________
Rajkumar Rajangam

View solution in original post

0 Likes
5 Replies
Highlighted
Knowledge Partner
Knowledge Partner

Re: WebElement: Getting the innertext property dynamically

Jump to solution

Is it possible that your Webelement properties innertest is used to identiofy it, thus when it changes from "Fr. 0.00" the WebElement is no longer valid.

What about doing something like:

While  Browser("xxx").Page("xxx").WebElement("xxx").Exist
    Wait(1)
Wend
newVal = Browser("xxx").Page("xxx").WebElement("html tag:=TD",InnerText:="Fr.*").GetROPRoperty("innerText")

You might have to change the html tag to match the tag of the WebElement and you might have to use an index if there are multiple currency fields.

MArk Smith.

 

 

 

0 Likes
Highlighted
Honored Contributor.. Honored Contributor..
Honored Contributor..

Re: WebElement: Getting the innertext property dynamically

Jump to solution

Hello,

Thank you for your answer. 

Actually, the innertext property is indeed used to identify the object but I used a regular expression "Fr\. .*" so it should still be valid.

I played a little more with the code and I found out that the problem comes from the code being executed inside a sub. If I take the code out of the sub and execute it, it works fine. The code exits the loop as soon as the innertext property changes. 

I tried to change the sub definition in order to pass the test object by reference like this: 

Sub TEND_ObjectPropertyValue(byVal transName, ByRef testObject, ByVal objectProperty, byVal objectPropertyValue)

But it still doesn't work. 

I feel like I must be missing something really basic here but I don't see it.

0 Likes
Highlighted
Knowledge Partner
Knowledge Partner

Re: WebElement: Getting the innertext property dynamically

Jump to solution

Here's a simple example that might help:

Call X(Browser("micClass:=Browser").Page("micClass:=Page"))

Function X(obj)

x=obj.GetROProperty("title")
MsgBox x

End Function

Mark Smith.

0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

Re: WebElement: Getting the innertext property dynamically

Jump to solution

Since the Object is refreshed after your first operation, you should use the RefreshObject method as given below.

Sub TEND_ObjectPropertyValue(transName, testObject, objectProperty, objectPropertyValue)
    
   While UCase(Trim(CStr(testObject.getROProperty(objectProperty)))) = UCase(Trim(CStr(objectPropertyValue)))
       If DateDiff("s", perf_timer_starttime, now) > perf_timer_timeoutsec Then
           ExitTest
       End If

       testObject.RefreshObject
    Wend
    
End Sub

Check this article for more details.

_____________________
Rajkumar Rajangam

View solution in original post

0 Likes
Highlighted
Honored Contributor.. Honored Contributor..
Honored Contributor..

Re: WebElement: Getting the innertext property dynamically

Jump to solution

This works like a charm, exactly what I was looking for :-))

Thanks a lot for your help. 

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.