Internet Explorer Automation Object Crossframe Element Troubles

Daniel E. Burrow danieleburrow at yahoo.com
Thu Jul 18 20:58:30 EDT 2002


Greetings!

Python Rocks! Now I feel better...

Mr. Hammond's win32com extensions positively enthuse me as I continue
to discover how they empower a OOP newbie whose long history includes
VB, Perl, and QBasic.

My present joy is to develop an automated monitoring tool that
launches IE, logs on, and then navigates through our SSL-enabled web
application.

Thus far development has been rapid until I wanted to simulate a user
clicking on a <span>onclick=doChange('gotonewurl')</span>. Since our
app utilizes frames, I need to specify the frame and element that
needs to be clicked.

Like a good trooper, I studied the resources at:

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&safe=off&group=comp.lang.javascript

http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/reflist_vb.asp?frame=true

http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/objects/frame.asp?frame=true

I found one who was doing what I am doing but it just causes my gut to
twist.

I am able to fire cross-frame elements now but doing so in the manner
shown in the *** ClickCrossFrameElement *** method below troubles me
greatly:

######### note the code is snipped in several places #############

import os, sys
from time import sleep, localtime, strftime
from mx.TextTools import *
from cls_AleCommonErrorHandler import AleCommonErrorHandler
from cls_AleCommonCommandLineInterface import
AleCommonCommandLineInterface
from cls_AleCommonRegistryInterface import AleCommonRegistryInterface
from cls_AleCommonOracleInterface import AleCommonOracleInterface

import win32com.client
import pythoncom

class AlerioWebReporter:
    """
    A class providing navigating, element fillin, and page
verification of
    web applications. If a page's contents does not contain the
specified
    search string, a record will be posted to the 
    "xxx.tb_ale_webreporter_run_reportable" Oracle database table.
    """

    ClassCount = 0

    def __init__(self):
        """
        AlerioWebReporter constructor initializes each data member to
nothing
        """
        AlerioWebReporter.ClassCount += 1
        print 'AlerioWebReporter: ClassCount:',
AlerioWebReporter.ClassCount

############################ Set methods go here
##########################

    def SetIE(self):
        self.o_IE = win32com.client.DispatchEx("InternetExplorer.Application")
        self.o_IE.Visible = 1

    def lots of other methods not shown(self):
        self.xyz

############################ Get methods go here
##########################

    def lots of other methods not shown(self):
        self.xyz

############################ Other methods go here
##########################

    def ClickCrossFrameElement(self, i_FrameId, s_ElementNameOrId):
        print 'i_FrameId', i_FrameId, 's_ElementNameOrId',
s_ElementNameOrId
        o_IE_Frame_Element =
self.o_IE.Document.frames[i_FrameId].document.all(s_ElementNameOrId).click()

        ## in ASP this was done as: 
        ## parent.frames[FrameId].document.all(s_ElementNameOrId).click()

############################# destructor goes here
#####################

    def __del__(self):
        del self.o_ErrorHandler
        del self.o_CommandLine
        del self.o_RegInterface
        del self.o_DbInterface
        del self.o_IE
        print 'Destroyed: AlerioWebReporter,
AlerioWebReporter.ClassCount
        AlerioWebReporter.ClassCount -= 1

############################ Main here ##########################

def main():
    ##clear the screen
    os.system('cls')
    ##instantiate
    o_AleApp = AlerioWebReporter()
    ##set
    o_AleApp.SetAleAppWebReporter()
    
    ##get the values
    at_SQLRunMbrConfigResults =
o_AleApp.GetAleAppFileReporterRunMbrConfigVals()
    if len(at_SQLRunMbrConfigResults) >= 1:
        i_RowCount = len(at_SQLRunMbrConfigResults)
        i_Row = 0
        while i_Row <= (i_RowCount -1):
            i_Col = 0
            s_URLId = at_SQLRunMbrConfigResults[i_Row][i_Col]
            i_Col +=1
            s_URL = at_SQLRunMbrConfigResults[i_Row][i_Col]
            i_Col +=1
            s_URLNavOrder = at_SQLRunMbrConfigResults[i_Row][i_Col]
            i_Col +=1
            s_PostNavEventsFlag =
upper(at_SQLRunMbrConfigResults[i_Row][i_Col])

            ##now set the currently running id member
            o_AleApp.SetRunningRunIdMember(s_URLId)
                
            o_AleApp.NavigateIE(s_URL)
            ##fire events after nav?
            print "There are", o_AleApp.GetIEDocumentAllObjectCount(),
"elements on", o_AleApp.GetIELocationURL()
            o_AleApp.ClickCrossFrameElement(1, 'Sub1t')

            i_Row += 1
            

    else:
        s_Error = 'No Results found for: SQL:' + s_SQL + ' Params: ' +
str(at_SQLParams)
        o_AleApp.WriteErrorHandlerRecord('ERROR', s_Error)
        print s_Error
        os.sys.exit()
        

    del o_AleApp

if __name__ == '__main__':
    main()



Joyfully About Alerio's Business,

Daniel Burrow



More information about the Python-list mailing list