Jump to content
Sign in to follow this  
LucasZ

Issues with AutoLogin for Web

Recommended Posts

LucasZ

Hey everyone, so my problem is that I'm trying to setup a script that will automatically login to a website.  The site itself I think is my main challenge in that it takes a few seconds to load after even IE thinks it's fully loaded.  I've tried adding a sleep timer in to combat this, but it doesn't seem to help.  If I run the script initially it opens IE and then I get an error as follows:

Line 1784 (File "C:\Program Files (x86)\AutoIt3\IE.au3"):

Return SetError($_IESTATUS_Success, 0, $oObject.document)
Return SetError($_IESTATUS_Success, 0, $oObject^ ERROR

Error:  The requested action with this object has failed.

The script I have is as follows:

#include <IE.au3>

Local $url = "http://website" ;This is the actual website address
Local $oIE = _IECreate ( $url, 1)

;Sleep(10000)

_IELoadWait($oIE)

Local $oForm = _IEFormGetCollection($oIE, 0)

$oQuery1 = _IEFormElementGetObjByName ($oForm, "x-auto-12-input")

$oQuery2 = _IEFormElementGetObjByName ($oForm, "x-auto-13-input")

$TargetUsername = "Yourusername"

$TargetPassword = "yourpassword"

_IEFormElementSetValue ($oQuery1,$TargetUsername)

_IEFormElementSetValue ($oQuery2,$TargetPassword)

$oButton=_IEGetObjById($oIE,"")

_IEAction ($oButton, "click")

_IELoadWait($oIE,0)

If, when the initial script errors out, I run the script a second time without closing the browser window the user name and password both populate without issue.  The button click is another story, but until I can get the username and password to load on the initial script run I won't worry about that.

I'm not entirely sure why the status can't be read and even if I take out the _IELoadWait($oIE) it doesn't seem to really help.  Any help would be greatly appreciated.  I'm just not sure what the deal is.

Edited by LucasZ

Share this post


Link to post
Share on other sites
LucasZ

Also, if I use the following script instead, it seems to avoid the error and does properly navigate tot he site, but then won't enter the credentials specified:

#include <IE.au3>

Local $url = "actualurl"
Local $oIE = _IECreate()

_IELoadWait($oIE)

_IENavigate ($oIE, $url, 1)

_IELoadWait($oIE)

Sleep (5000)

Local $oForm = _IEFormGetCollection($oIE, 0)

$oQuery1 = _IEFormElementGetObjByName ($oForm, "x-auto-12-input")

$oQuery2 = _IEFormElementGetObjByName ($oForm, "x-auto-13-input")

$TargetUsername = "Yourusername"

$TargetPassword = "yourpassword"

_IEFormElementSetValue ($oQuery1,$TargetUsername)

_IEFormElementSetValue ($oQuery2,$TargetPassword)

$oButton=_IEGetObjById($oIE,"")

_IEAction ($oButton, "click")

_IELoadWait($oIE,0)

Share this post


Link to post
Share on other sites
Danp2

It's likely that the IE object is going out of context (switch from http to https, etc). So you will likely need to reestablish the connection using _IEAttach after the initial _IENavigate.

Share this post


Link to post
Share on other sites
LucasZ

I can't seem to get _IEAttach to work either.  I tried using the window title, the URL, etc..no good.  It still won't input the credentials.

Share this post


Link to post
Share on other sites
LucasZ

I'm not really getting any errors, it's just not inputting the credentials.  The code is:

 

#include <IE.au3>

Local $url = "actualurl"
Local $oIE = _IECreate()
Local $TargetUsername = "Yourusername"
Local $TargetPassword = "yourpassword"

;_IELoadWait($oIE)

_IENavigate ($oIE, $url, 1)

$oIE = _IEAttach ( "title" ) ;also tried with URL instaed of title and Local $oIE = _IEAttach ( "title or url" )

_IELoadWait($oIE)

Local $oForm = _IEFormGetCollection($oIE, 1)

$oQuery1 = _IEFormElementGetObjByName ($oForm, "x-auto-12-input")

$oQuery2 = _IEFormElementGetObjByName ($oForm, "x-auto-13-input")

_IEFormElementSetValue ($oQuery1,$TargetUsername)

_IEFormElementSetValue ($oQuery2,$TargetPassword)

;$oButton=_IEGetObjById($oIE,"")

;_IEAction ($oButton, "click")

;_IELoadWait($oIE,0)

 

Of course, the page comes up, the website appears, but nothing will enter in.

Edited by LucasZ

Share this post


Link to post
Share on other sites
Au3Builder

I haven't written anything using ie.au3 library for a long time but try to mess with these functions.

_IEGetObjById\_IEGetObjByName  + IEPropertySet("innertext or innerhtml")

 

as far as i remember _IEForm does not always function with forms.

Edited by Au3Builder

Share this post


Link to post
Share on other sites
jdelaney

Add in error handling and logging to see exactly what function isn't finding it's element.  use isobj as the validator.


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
LucasZ

I honestly wanted to make this a more sophisticated script, but since I was having these issues as specified and without spending a ton of time sending out logs and everything else I just decided to go with the less sophisticated version of the script as follows:

 

#include <IE.au3>

Local $url = "actualrul"
Local $oIE = _IECreate ($url, 1)

$TargetUsername = "Yourusername"

$TargetPassword = "yourpassword"

_IELoadWait($oIE)

Sleep (5000)

Send ($TargetUsername)

Send ("{TAB}")

Send ($TargetPassword)

Send ("{ENTER}")

 

This seems to work as desired.  

Share this post


Link to post
Share on other sites
jdelaney

It will work, but not consistently. Each consolewrite would take less time than it did for you to post that.


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

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  

×