Jump to content

Problem with _IELoadWait and the @error flag


Recommended Posts

Hey guys,

I have written a script that automates my login process for a bunch of websites, it works great, however if I close the browser window before the script finishes the login it get stucks and I have to kill the process.

Now here is the code.

Case $MSG[0] = $theloginbutton
        While $goagain = 0
            $USERNAME = GUICtrlRead($theusername)
            $PASSWORD = GUICtrlRead($thepassword)
        
            $BW = _IECreate("the url", 0 , 1, 0)
            _IELOADWAIT($BW,0,10000)
            MsgBox(0,"","-"&@error&"-")
            If @error = 6 Then
                MsgBox(0,"","exited")
                Exitloop
                $goagain = 1
            EndIf
            
            While _IEPROPERTYGET($BW, "busy")
                Sleep(500)
            WEnd
            MsgBox(0,"",""&@error&"")
            $OSUBMIT = _IEGETOBJBYID($BW, "txtUserId")
            MsgBox(0,"",""&@error&"")
            _IEFORMELEMENTSETVALUE($OSUBMIT, $USERNAME)
            MsgBox(0,"",""&@error&"")
            _IELOADWAIT($BW,0,10000)
            MsgBox(0,"",""&@error&"")
            While _IEPROPERTYGET($BW, "busy")
                Sleep(500)
            WEnd
            $OSUBMIT = _IEGETOBJBYID($BW, "txtPassword")
            _IEFORMELEMENTSETVALUE($OSUBMIT, $PASSWORD)
            While _IEPROPERTYGET($BW, "busy")
                Sleep(500)
            WEnd
            $OSUBMIT = _IEGETOBJBYID($BW, "btnLogin")
            _IEACTION($OSUBMIT, "click")
            
            WinWait("Windows Internet Explorer","You are already logged in",3000)
            ControlClick("Windows Internet Explorer","You are already logged in","[CLASS:Button; INSTANCE:1]","primary")
            
            _IELOADWAIT($BW,0,10000)
            $OSUBMIT = _IEGETOBJBYID($BW, "BranchID")
            _IEFormElementOptionselect( $OSUBMIT,"110")
            While _IEPROPERTYGET($BW, "busy")
                Sleep(500)
            WEnd
            
            $OSUBMIT = _IEGETOBJBYNAME($BW, "B1")
            _IEACTION($OSUBMIT, "click")
                       $goagain = 1
        WEnd

To test this I click theloginbutton to launch the IE window and then close it manually and wait for the _IELoadWait to time out

I added the timeout of 10 seconds to _IELoadWait and that is supposed to return the @error code of 6, and it does as proven by the MsgBox I put in, but when I use

If @error = 6 Then
                MsgBox(0,"","exited")
                Exitloop
                $goagain = 1
            EndIf

It does not catch it. I can not figure out why.

Also, if there is an easier way to figure out if the browser was closed and abort the rest of this one case that would be great.

Thanks in advance.

Link to comment
Share on other sites

Thanks! That seems to work just fine except for one thing.

It exits the entire program. What I would like to do is end just that one case and go back to waiting for for input from the GUI. I tried to use ExitLoop instead of Exit, but I get an error that says ExitLoop is not allowed. I have looked over the help file about 10 times looking for anyway to end one specific case and go back to waiting for input from the GUI but I can not find anything.

Link to comment
Share on other sites

Put the case functionality in a function body and call it with either true or false. In the Adlib function you can call this function with false if the hwnd is not pointing to an existing window instead of exiting the script, this way you need to define sort of 1 iteration loop structure. Example:

Case $Something
     Function(True)
.
..
...

Func Function($fResume)

     While $fResume
             ; Some IE functionality.
             ; May get stuck right here or resume to...
             $fResume = False
     WEnd
EndFunc

Func AdLib()
     Local $hWnd = _IEProperyGet($oIE, "HWND")
     If Not IsHWnd($hWnd) Then Function(False)
EndFunc

I didn't check it though.

Edited by Authenticity
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...