Jump to content
Sign in to follow this  
Coded4Decades

how to wait for _ieQuit($oIE) to finish

Recommended Posts

Coded4Decades

I'm sure this is question easy, but I am new to Autoit so I can't figure it out.

My main loop has a very complicated internet explorer script that is causing me a lot of problems. (Please, don't ask me for details about that complicated code, it is irrelevant to this question, and is hard to explain.)

I got my complicated code to work by closing the previous internet process at the beginning of the loop.

But, I discovered that _ieQuit runs asynchronously, so I had to put in a sleep(5000)  [sleep(2000) was NOT long enough -- things still went wrong!!!].

The script runs fine, but it is very slow .

So, I want to know how to wait for the _ieQuit to finish.

Something like this

set $oIE = _IeCreate

while $moreToDo

  _ieQuit($oIE)

   while $oIE.readystate  <> 4 ;  <<== this is how I do it in vba, but it didn't work in Autoit. It said $oie was not an object

       sleep(100)

   wend

   if processexists("iexplorer.exe") then   ; 

       exit 9999 ; error condition which should never happen.

   endif

    set $oIE = _ieCreate

,,,, complicated code

wend

Edited by Coded4Decades

Share this post


Link to post
Share on other sites
Prime03

As far as I'm aware, your script will not continue until after _IEQuit has returned, and calling the .quit method on IE is almost instantaneous, but if you need to be super sure, you could always slap a while loop after it check for the process...

_IEQuit($oIE)
 
While ProcessExists ("iexplorer.exe") <>  0 
sleep(100)
WEnd
Edited by Prime03

Share this post


Link to post
Share on other sites
jdelaney

Make sure you wait for your process to close, and not just any IE...else, you might never exit the loop...unless you are absolutely certain there will only be one IE during execution.

#include <WinAPI.au3>
$hIE = _IEPropertyGet($oIE,"hwnd")
$iPID = ""
 _WinAPI_GetWindowThreadProcessId($hIE,$iPID)
_IEQuit($oIE)


While ProcessExists ($iPID) <>  0 
    sleep(100)
WEnd
Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
Coded4Decades

Regarding <<IEQuit is super>> 

Well, during last week's testing it looked like I needed the sleep(3000).   But today, I discovered it was becaise my IE was Visible.  If I left IE invisible, the IEQuit was much faster.

But, to be on the safe side, I posted this question. Both of your responses work for me.

The addition of the Hwnd lookup is a nice touch which makes the code slightly safer, so that is the version I am using.

Thanks for your help.

Edited by Coded4Decades

Share this post


Link to post
Share on other sites
Coded4Decades

Universalist:  have you made any changes to your IE macro recorder? I am going to try it out and want to use the most recent version.

Share this post


Link to post
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
Sign in to follow this  

×