Jump to content

AutoIt doesn't submit all HTTP request parameters


Recommended Posts

I am trying to automate logging into a web application. It requires

- username

- password

- domain

- account number

I am using the IE.au3 library so far. Here is my autoit script

#include <IE.au3>
AutoItSetOption("WinTitleMatchMode", 2)
; Create a browser window and navigate to the web app
$oIE = _IECreate()
_IENavigate($oIE, "http://webapp/login.html")

$o_form = _IEFormGetObjByName($oIE, "login")
$o_userid = _IEFormElementGetObjByName($o_form, "userid")
$o_password = _IEFormElementGetObjByName($o_form, "password")
$o_domain = _IEFormElementGetObjByName($o_form, "domain")
$o_accountNumber = _IEFormElementGetObjByName($o_form, "accountNumber")

; Set field values and submit the form
_IEFormElementSetValue($o_userid, "myUserName")
_IEFormElementSetValue($o_password, "myPassword")
_IEFormElementSetValue($o_domain, "myDomain")
_IEFormElementSetValue($o_accountNumber, "11111")

; Submit the form
_IEFormSubmit($o_form)

Here is an extract of the HTML page

<form action="/WebAppLogin.asp?" method="post" name="login" onsubmit="return login_onsubmit()" autocomplete="off">
    
<input name="userid" id="userid" style="BACKGROUND-COLOR: linen; WIDTH: 180px">
<input type="password" id="password" name="password" style="BACKGROUND-COLOR: linen; WIDTH: 180px">
<select name="domain" id="domain" style="BACKGROUND-COLOR: linen; WIDTH: 180px" onblur="java script: void setCapsLock();" onkeydown="account_onkeydown()" onkeypress="if (event.keyCode==13) if (login_onsubmit()==true) login.submit();">
          <option value="">- Select - </option>
    <OPTION VALUE='myDomain'>My Domain</OPTION>
</select>
<input disabled name="accountNumber" ID="accountNumber" style="BACKGROUND-COLOR: linen; WIDTH: 180px" value="" onkeypress="if (event.keyCode==13) if (login_onsubmit()==true) login.submit();">

Now when I run this script, it doesn't seem to submit the accountNumber value as a parameter in the POST. Hence it results in a failed login. I ran the script in conjunction with Fiddler and Fiddler only gives parameter values for username, password and domain (accountNumber parameter is missing). If I comment out the FormSubmit, the accountNumber is populated with the correct value, and if I press the login button manually on the login page, the login process works and Fiddler can pick up the accountNumber parameter value. However I am a bit bemused as to why AutoIt doesn't submit the accountNumber parameter in the request and why Fiddler cannot detect it. Is it something to do with the fact that the accountNumber field in the HTML is a disabled field? AutoIt sets the value of the disabled field without problems and I can submit the login manually. I have placed Sleep(1000) before the FormSubmit, without success.

Does anyone have an idea as to how/why its not picking up the field value? Thanks in advance.

Link to comment
Share on other sites

Maybe Javascript is doing something tricky upon submission:

login_onsubmit()

Manual submission is done with Javascript, AutoIt is submitting the form without it.

Yes you are right, thank you. I have implemented clicking the login button using the mouse.

$oSubmit = _IEGetObjByName ($oIE, "LoginButton")
_IEAction ($oSubmit, "click")

Perhaps AutoIt should handle the Javascript automatically? I haven't looked at the Javascript to see what was going on, just as long as it works in the end. :P

Link to comment
Share on other sites

Yes you are right, thank you. I have implemented clicking the login button using the mouse.

$oSubmit = _IEGetObjByName ($oIE, "LoginButton")
 _IEAction ($oSubmit, "click")

Perhaps AutoIt should handle the Javascript automatically? I haven't looked at the Javascript to see what was going on, just as long as it works in the end. :P

The _IEFormSubmit function sends the form just as an html form would be sent, Javascript submit() should do the same thing. The issue here is that another Javascript function (login_onsubmit()) is called before submit(). My guess is that function doctors up some form elements prior to submission.

You will have to look at the JS source code, I think there is a way to call a string of Javascript manually through the IE object.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...