Geeks With Blogs

News QTP and Stuff
Theo Moore Questions... Morphology? Longevity? Incept dates?

I am working on a DLL that I can call that will open an instance of Internet Explorer, and then return its Browser handle and Page handle. I am trying to write procedures that will handle functionality totally independent of the text in the title, the text on the page, or whatever else QTP uses to reference these objects. Basically, I am frustrated having to fix regular expressions or whatever to make sure my references work. It seems like a no-brainer to me that I should be able to open a browser, and get the handles to the browser and the page (only one assuming IE 6) underneath it. Yes, I can use the GetROProperty to get that value, but it assumes that the property I use to get the value hasn't changed or isn't determined dynamically. If it has, this doesn't work reliably.

Just a quick design criticisim of QTP: Why in the world there isn't a built-in function called “OpenBrowser” I'll never know. That function should return the handles to you. However, there isn't. So, here I am working to write it myself.

I have a rough set of code that does exactly what I want, but I need to refactor it (read as: make into something less ugly) before I use it. Whilst I was working on this, I found something interesting:

If you use a late-bound instance of internet explorer (CreateObject(”InternetExplorer.Application”)) vice an early-bound, QTP will *not* have any clue how to interact with it. If you try to object spy the fields on it, it will tell you that you are looking at WinApp and a WinObject (Browser and Page) and referring to the objects via handle will fail. Basically, QTP will not be able to determine what they are. Seems to me it would know by asking what the class is by using the handle it can get. I mean, that's what I do in my code to get the the correct handle in the first place. If you use the early-bound method, this works fine. Interesting, but the pity that the code would have to written in VB and compiled rather than use VBScript. 'Course, I am using callback API functions in the code, so I am stuck doing VB anyway.

Just something I hope I can relate to save someone else a few hours of pain.

Posted on Monday, May 1, 2006 1:04 PM | Back to top


Comments on this post: QTP: Early vs. Late Bound objects in DLL

# re: QTP: Early vs. Late Bound objects in DLL
Requesting Gravatar...
I don't understand exactly what you are trying to do with a VB DLL. But you are looking for a function that opens a IE browser window and navigate to URL and returns back a reference to the opened browser/page that can be done using VBScript itself - which I am sure you are aware of. Can you elaborate more on what you are trying to achieve?

Normaly, I use a function as,

I don't understand exactly what you are trying to do with a VB DLL. But you are looking for a function that opens a IE browser window and navigate to URL and returns back a reference to the opened browser/page that can be done using VBScript itself - which I am sure you are aware of. Can you elaborate more on what you are trying to achieve?

Normaly, I use a function as,

<pre>
Function OpenBrowser(byval URL, byref BrowserPage)
Dim oIE, IEBrowser, IEPage
Dim WaitCount

Set oIE = CreateObject("InternetExplorer.Application")
oIE.visible = 1
oIE.Navigate2 URL

WaitCount = 0
Do While oIE.ReadyState <> 4 And WaitCount < 5
Wait(1)
WaitCount=WaitCount+1
Loop

If oIE.ReadyState <> 4 Then
OpenBrowser = False
Exit Function
End If

Set BrowserPage = Browser("hwnd:=" & oIE.hwnd).Page("title:=" & oIE.Document.Title)
OpenBrowser = True
End Function

Dim ymailBrowserPage
If OpenBrowser("http://mail.yahoo.com", ymailBrowserPage) Then
MsgBox "Browser Opened Successfully!"
ymailBrowserPage.WebEdit("html id:=username").Set "success"
Else
MsgBox "Failed to open the browser"
End If
</pre>
Left by Partha on May 02, 2006 7:02 AM

# re: QTP: Early vs. Late Bound objects in DLL
Requesting Gravatar...
Yes, that actually looks a lot like what I've written. The only stumbling block I've seen is the Page.title. It isn't always reliable to get at the objects in the page. I've also run into trouble with QTP recognizing the Browser as a browser when the object is instantiated late-bound rather than early bound; instead it returns a WinApp.

I use the XMLDocument quite a bit to get at things on the page; the document.title might be a simpler way. I've give this a looksee.

Thanks for you input and time to answer!
Theo
Left by Theo on May 02, 2006 1:09 PM

# How can construct Object Spy
Requesting Gravatar...
Any Buddy Help meeeeeeeeeeeee...

How can construct a tool which read or recognize properties of other object
Left by Rohit on Mar 11, 2007 11:08 PM

# How can construct Object Spy
Requesting Gravatar...
Any Buddy Help meeeeeeeeeeeee...

How can construct a tool which read or recognize properties of other object
Left by Rohit on Mar 11, 2007 11:08 PM

Comments have been closed on this topic.
Copyright © Theo Moore | Powered by: GeeksWithBlogs.net