Coded4Decades Posted February 19, 2014 Posted February 19, 2014 (edited) 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 February 19, 2014 by Coded4Decades
Prime03 Posted February 19, 2014 Posted February 19, 2014 (edited) 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 February 19, 2014 by Prime03
Solution jdelaney Posted February 19, 2014 Solution Posted February 19, 2014 (edited) 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 February 19, 2014 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.
Coded4Decades Posted February 20, 2014 Author Posted February 20, 2014 (edited) 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 February 20, 2014 by Coded4Decades
Coded4Decades Posted February 20, 2014 Author Posted February 20, 2014 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now