Facebook

Course Name Start Date Time Duration Registration Link
No Training Programs Scheduled ClickHere to Contact
Please mail To sudhakar@qtpsudhakar.com to Register for any training

Thursday, September 3, 2009

Working with Existing Browser Using DOM

Working with Existing Browser Using DOM

As all know that CreateObject("internetexplorer.application") is to create a new browser instance and on that we can perform all DOM operations.

'*******************************************
'This script will open a new browser

Set IE=CreateObject("internetexplorer.application")
IE.Visible=True
IE.Navigate "http://google.com"

'*******************************************

So how to work with an existing browser. Means there is an opened browser and i need to do some operations on that using DOM. In this case we can use Shell object to get the current opened browser windows.

The below function will give you the opened browser instance.

'Calling the function

Set oBrowser=GetControlonBrowser("Google")

'*******************************************
Function GetControlonBrowser(BrowserTitle)
Dim objShell
Dim objShellWindows
Dim wnd
Dim oBrowserIdentified

Set objShell = CreateObject("Shell.Application")
Set objShellWindows = objShell.Windows

For Each wnd In objShellWindows
        If wnd.name= "Windows Internet Explorer" Then
                If trim(lcase(wnd.document.title))=
trim(lcase(BrowserTitle)) Then
                        Set GetControlonBrowser=wnd

oBrowserIdentified=True
Exit For
                End If
        End if
Next

If not
oBrowserIdentified then
msgbox "Browser Not Identified"
End If

Set objShell = Nothing
Set objShellWindows = Nothing
End Function

'*******************************************

I have given a sample
DOM script on Google Search. That script will work by creating a new browser instance.
Click here to see Sample DOM Script On Google Search
Use this function in that script to work with an opened browser.

Using the above function in Sample DOM Script

'Instead of the  below code use
Set PageObject=GetControlonBrowser("Google").Document
'********************************************************
Set IE=CreateObject("internetexplorer.application")
IE.Visible=True
IE.Navigate "http://google.com"
BrowserSync(IE)
Set PageObject=IE.Document

'********************************************************

Please send your Suggestions, Doubts about my blog and posts to my yahoo group http://in.groups.yahoo.com/group/qtpsudhakar



No comments :

Post a Comment