Jump to content

Unable to attach an IE Instance


Recommended Posts

Hi all 

 

I've tried some stuff to attach an ie window however it fails repeatedly  

 

This is in the main file where I used a com error notify function to handle IE errors 

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")    ; Initialize a COM error handler

;Turn ie errors off
_IEErrorNotify(true)

_COMError_Notify(2)

Func _COMError_Notify($iDebug, $sDebugFile = Default)

    Static Local $avDebugState[3] = [0, "", 0] ; Debugstate, Debugfile and AutoIt.Error object
    If $sDebugFile = Default Or $sDebugFile = "" Then $sDebugFile = @ScriptDir & "\COMError_Debug.txt"
    If Not IsInt($iDebug) Or $iDebug < -1 Or $iDebug > 3 Then Return SetError(1, 0, 0)
    Switch $iDebug
        Case -1
            Return $avDebugState
        Case 0
            $avDebugState[0] = 0
            $avDebugState[1] = ""
            $avDebugState[2] = 0
        Case Else
            If $iDebug = 2 And $sDebugFile = "" Then Return SetError(4, 0, 0)
            ; A COM error handler will be initialized only if one does not exist
            If ObjEvent("AutoIt.Error") = "" Then
                $avDebugState[2] = ObjEvent("AutoIt.Error", "__COMError_Handler") ; Creates a custom error handler
                If @error <> 0 Then Return SetError(2, @error, 0)
                $avDebugState[0] = $iDebug
                $avDebugState[1] = $sDebugFile
                Return SetError(0, 1, 1)
            ElseIf ObjEvent("AutoIt.Error") = "__COMError_Handler" Then
                Return SetError(0, 0, 1) ; COM error handler already set by a previous call to this function
            Else
                Return SetError(3, 0, 0) ; COM error handler already set to another function
            EndIf
    EndSwitch
    Return

EndFunc   ;==>_COMError_Notify


   ;/******************************************************/
   ;/*****************Main Program*************************/
   ;/******************************************************/
Test1TestMainPage($IEURL, "user", "password")

 

This is the function which starts the test 

 

It's pretty simple but the If @extended bit always creates a new browser and the If@error after the _IeAttach function always says can't attach window 

 

Which then means the IEFormSetvalue functions fail too 

 

Func Test1TestMainPage($IEURL, $User, $Password)

   ;/************************* Start URL for compliance letters **************************/
Local $oIE = _IECreate($IEURL)
If @extended Then
    MsgBox($MB_SYSTEMMODAL, "", "Attached to Existing Browser")
Else
    MsgBox($MB_SYSTEMMODAL, "", "Created New Browser")
EndIf

Sleep(10000)
if WinSetState($ApplicationWindow, "", @SW_MAXIMIZE) Then


Else
   Sleep(6000)
   WinSetState($ApplicationWindow, "", @SW_MAXIMIZE)
EndIf

WinActivate($ApplicationWindow)
_IEAttach("Online - Internet Explorer")
If @error Then
   MsgBox(64, "Error handling", "Can't attach IE window")
EndIf
 ;/****************************End*************************************************************/

;/****************************Test main page*********************************************/
;Get the object IDs to be used in manipulating them
_IELoadWait($oIE)
Sleep(10000)

Local $LoginPageID= _IEGetObjById($oIE, "wrapper")
Local $UserNameID = _IEGetObjById($oIE,"ctl00_cphBody_Login1_Label1")
Local $PasswordID = _IEGetObjById($oIE,"ctl00_cphBody_Login1_Label2")

;Tests main header
CompareOnInnerText_SearchViaTagNameCollection($oIE, "Username", "td")
;CheckAField_In_InternetExplorer_On_Inner_Text($UserNameID, "UserName:", "Observe Username header is correct")
;CheckAField_In_InternetExplorer_On_Inner_Text($PasswordID, "PasswordID:", "Observe Password header is correct")
;Check_A_Field_Contains_In_InternetExplorer($PasswordID, "PasswordID:", "Observe Password header is correct")

Local $UserNameInputID = _IEGetObjById($oIE,"ctl00_cphBody_Login1_UserName")
Local $PasswordInputID = _IEGetObjById($oIE,"ctl00_cphBody_Login1_Password")

;input username and password
Sleep(4000)
_IEAction($UserNameInputID, "focus")
_IEFormElementSetValue($UserNameInputID, $User)
      if @error Then
         Msgbox(64, "Error handling", "Can't input username to username box")

         EndIf
_IEFormElementSetValue($PasswordInputID, $Password)
        if @error Then
               Msgbox(64, "Error handling", "Can't input password to username box")

               EndIf

so what can I do to ensure it attachs correctly? 

Edited by CaptainBeardsEyesBeard
Link to comment
Share on other sites

_IECreate($IEURL, 1) to attach

You also don't declare $oIE = _IEAttach("-SNIP- Online - Internet Explorer"), so $oIE is looking at your previous object.

Edited by Jos
Edited on request of OP
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...