For any corporate training requirements Please mail To sudhakar@qtpsudhakar.com
Course Name Date Time Duration Type Location
An important update from QtpSudhakar. I stopped giving classroom training in MindQ Systems. I have bigger plans and I want to put an end to regular classroom training because very less people are practicing. From now onwards every session of mine is going to have explanation and practice. Everyone should practice in presence of mine and should go out of classroom with practical knowledge. So I started my own institute AnyTechLabs in Madhapur. Please reach out to +91-8328152362 for course details. Visit AnyTechLabs.com for address details.
Selenium + Cucumber 24th October 7.30 AM IST to 9.00 AM IST 45 Days WeekDay Online

A book "Cracking the QTP interview" authored by Sudhakar.Read More. Buy From FlipKart

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.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

Exit For
                End If
        End if

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.Navigate "http://google.com"
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