dwsndev
dwsndev

Reputation: 790

AutoIt v3: _IENavigate + _IELoadWait Not Working as Expected?

This code is supposed to open a new browser set at "www.website.com," submit a username and password, wait for the page to load after being submitted, navigate to a new page, and inject a javascript code into the address bar.

My current results from this code are opening a new browser set at "www.website.com," submit a username and password. The submit works, then from here, the code breaks and instead of navigating to the next page (page2) it just hangs.

Even when I add an ignore command to the _IEFormSubmit($oForm) I can't get my page to navigate to the next page.

#include <IE.au3>

#RequireAdmin

Local $oIE = _IECreate("http://www.website.com")
;_IELinkClickByText($oIE, "Sign In") ;Optional
Local $oForm = _IEFormGetObjByName($oIE, "regular-user-login-form")
Local $oText = _IEFormElementGetObjByName($oForm, "log")
_IEFormElementSetValue($oText, "username")
Local $oText = _IEFormElementGetObjByName($oForm, "pwd")
_IEFormElementSetValue($oText, "password")
_IEFormSubmit($oForm)

_IENavigate($oIE, "http://www.website.com/page2/")

Send("{F4}javascript:check_in();{ENTER}")

Please for the love of god, what am I doing wrong.

Edit: I've also changed the _IEFormSubmit($oForm) to another javascript submit and I can still log in without any problems, but once I reach that next page I can't use _IENavigate, so the problem has to lie there.

Upvotes: 0

Views: 2585

Answers (1)

Milos
Milos

Reputation: 2946

I have automated so many different pages and sometimes the script gets stuck on _IEFormSubmit for no reason. That's an AutoIt bug.

Her's a quick fix for that

_IEFormSubmit($oForm, 0)
_IELoadWait($oIE, 1000)

Your code should be:

#include <IE.au3>

#RequireAdmin

Local $oIE = _IECreate("http://www.website.com")
;_IELinkClickByText($oIE, "Sign In") ;Optional
Local $oForm = _IEFormGetObjByName($oIE, "regular-user-login-form")
Local $oText = _IEFormElementGetObjByName($oForm, "log")
_IEFormElementSetValue($oText, "username")
Local $oText = _IEFormElementGetObjByName($oForm, "pwd")
_IEFormElementSetValue($oText, "password")
_IEFormSubmit($oForm, 0)
_IELoadWait($oIE, 1000)

_IENavigate($oIE, "http://www.website.com/page2/")

Send("{F4}javascript:check_in();{ENTER}")

Onetime, I tried to report two bugs to autoit forum, but the guys who are there are pretty frustrated fellas. So, now when I find one, I just solve it my way.

Off topic:

When dealing with objects you should know of another bug

If $oInput.outertext = "Continue" then ...

The above code will sometime fail even if the outertext matches. This is solved using, use

If $oInput.outertext == "Continue" then ...

Upvotes: 1

Related Questions