QTP: GetROProperty vs. Page.Object

 

I strongly dislike waiting. This applies at the drugstore, the DMV, or any other place. I patiently accept that this happens, however, since life is just like that. I do try to avoid it whenever reasonably possible, especially at work.

 

Which explains why I try to never use a Wait() statement in QTP. Wait seems like a cop-out; rather than attempt to find that one property that indicates the state of my application, I’ll put pick a time and hope for the best. My linear-thinking, anal-retentive mind just can’t do it unless I have tried every other means imaginable (and unimaginable). It’s just how I am wired.

 

So, how does this relate to my title? Basically, I am often looking at Page/Browser object properties to determine my application state. However, I’ve noticed lately that the GetROProperty Function simply doesn’t work reliably. Here’s and example of what I mean:

 

With Browser("RE").Page("GEOMAP")

If Instr(UCase(.GetROProperty("url")), "GEOMAP") > 0 Then

.WebArea("alt:=" & DataTable.Value("A", dtLocalSheet)).Click

Do

Browser("RE").ClearDialogs()

Loop Until Browser("hwnd:=" & Environment("BrowserHandle")).Page("url:=" & Environment("RE_Web") & "\home-listings/default.asp?state=NC").Exist(1)

If Instr(Browser("hwnd:=" & Environment("BrowserHandle")).Page("url:=" & Environment("RE_Web") & "\home-listings/default.asp?state=NC").GetROProperty(“title”), “Test”) > 0 Then

<do something>

End If

.Sync

End If

End With

 

In this snippet, we are trying to determine if we are on the correct page using the .GetROProperty(url”). Sometimes this works, and sometimes it doesn’t. We later use a loop to determine if we are on the correct page post clicking on the correct WebArea. If we are, we use a custom solution to deal with popup dialogs and clear them all. We then attempt to access the title of the page to determine if we should do something else. Sometimes, even the descriptive programming in these cases won’t work correctly 100% of the time.

 

So what do you do? I am glad you asked! Normally, I rely on the Page.Object to determine my current state. This is a reference of the XMLDocument under the page, and is therefore usually more “up to the minute” than the functions that QTP provides natively. Using the above code, I could get at anything I could under the GetROProperty, and some I can’t. Easiest thing to do is use object spy in QTP to determine what’s available (much as you might for GetROProperty), but I also consult an XMLDocument reference to see if there is anything else there I can use. An example of how I would use the XMLDocument might be:

Browser("hwnd:=" & Environment("BrowserHandle")).Page("url:=" & Environment("RE_Web") & "\home-listings/default.asp?state=NC").Object.title

 

This method seems to work much more reliably that GetROProperty most of the time, and after all, who likes to wait?

«April»
SunMonTueWedThuFriSat
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456