Jump to content
Sign in to follow this  

attaching back to the original window

Recommended Posts

I have a application that I wrote that brings up IE and does a data import, it works if I am not at the computer and moving things around but as I soon as I try to work on the computer it fails because it can't find the object, what I have finally figured out is that because each process takes about 10 minutes to import and I have a different window open its failing, I "thought" that using _IEattach would do the trick but its not, am I missing something ? or should it be something else, this entire run takes about 45 minutes and it works if I run it at night but I would like to run during the day too and continue working on other things.

Partial code below


;lots of code above, IECreate and other stuff.


_IELinkClickByText ($oIE, "LOG OUT")

_IEQuit ($oIE)

FileClose($file);close log file

func doimport($XMLFile)

;sometimes failing IF I am at the computer and interacting because I have moved to

;a different window so lets try IEAttach to see if that re-grabs the window

$oIE = _IEAttach("Import Data")

;hopefully that line above has put the focus back into the proper window and the rest will work, it did NOT :)

;all the getobjs are failing because the main window is not the IE window

FileWriteLine($file, "Starting " & $XMLFile & @CRLF)

$oForm2 = _IEFormGetObjByName($oIE, "_ctl0")

$FileUp = _IEFormElementGetObjByName($oForm2, "FileUpload")

_IEAction($FileUp, "focus")



$oSubmit = _IEGetObjByName ($oIE, "ReadFileButton")

_IEAction ($oSubmit, "click")

_IELoadWait ($oIE)

;more code below


Edited by mikeyr

Share this post

Link to post
Share on other sites

I have been playing around and I have confirmed, if I start my code and walk away it works everytime. If I am at my desk and working it fails unless I make sure to click on the IE window that AutiIT opened before I get to the last record so that the script can continue.

So my issue is in my script I open a IE window, if I open any other window manually the script will fail. How do I force a re-attach to the original IE window so the code can continue, I thought _IEAttach would do it but its not :)

This is kind of important to me since this code takes about 45 minutes to run and I need to run it during the day effectively making me not able to use my computer during that time.

I have to be missing something right ?

Edited by mikeyr

Share this post

Link to post
Share on other sites

Couple things to point out... if you can, I always prefer using window handles to attach to IE instances... not everyone does but I feel you are less likely to have issues.

Also, if your page refreshes for any reason, you have to re-establish object variables, as they get destroyed in the refresh. For instance, after your page refreshes you have to call _IEFormGetObjByName again for $oForm2.

Let me know if this helps.

While ProcessExists('Andrews bad day.exe')

Share this post

Link to post
Share on other sites

Thanks, the screen is refreshing and I am calling IEformGetObjByName again, I ran into that during my testing.

I guess I have to look into using the window handles since I get _IEAttach to work, I have tried quite a large variation

$oIE = _IEAttach("Import Data", "WindowTitle")

$oIE = _IEAttach("Import Data - Windows Internet Explorer", "title")

$oIE = _IEAttach("Import Status", "text")

And quite a few others but those were the ones I thought should have worked, it seems I can't reconnect. It all works fine if I am not using my computer because then nothing moves away from the IE window but if I check e-mail, it crashes and I can't reconnect.

I guess my question now is what the point of IEAttach since I can't seem to make it work, am I understanding it incorrectly and using the wrong command ?

Going to look into finding the HWND at startup and re-connecting to it each time through my loop.

Share this post

Link to post
Share on other sites

GOT IT !!!

I looked into wingethandle and passing the handle and like that and found WinActivate in the help file, in my function I just call WinActivate and that is working, did not need HWnd from WinGetHandle. Now I can run this and check e-mail and work, way cool.

Of course this whole thing came about because I could not get IEDocInsertText to work on a "input type=file" type of field, it works on others but its working and I am happy.

What can I say, I am new to this and did not know winactivate existed although I still think that IEAttach should have worked.

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...