Jump to content

IE.au3 Error When Submitting Simple Form


BobSherman
 Share

Recommended Posts

I am attempting to enter the logon ID and password into the form below and submit it.

But, I am experiencing an error in IE.au3 whether I use _IEAction to submit a click (which does submit the form) or _IEFormSubmit (which does not submit the form before it errors out).

The form seems rather simple:

<form method="post" action="logon_submit.php">
                       <input type="hidden" name="visit" value="sRhvMItOu1hNV_y9t4iB7xhns2UJ0pUIYmpJyy3CivjvGYv0ST1QHY40QP9H5UPTqonadminkin_65dvtXxSIXDPwyFFI6WPVQFmgFtba8vW3OH">
<table width="100%" border="0" cellpadding="0" align="center" cellspacing="0">
                    <tr>
                      <td valign=top><table width="100%" border="0" cellpadding="4" cellspacing="1">
                          <tr>
                            <td align="Right"><b>Username: <span class="style1">*</span></b></td>
                            <td width="80%"><input type="TEXT" name="user" style="width: 90%;">
                            </td>
                          </tr>
                          <tr>
                            <td align="Right"><b>Password: <span class="style1">*</span></b></td>
                            <td><input type="password" name="pass" style="width: 90%;">
                            </td>
                          </tr>
                          <tr>
                            <td align="Right">&nbsp;</td>
                            <td><input type="submit" name="Submit" value="Submit Form">
                            </td>
                          </tr>
                          <tr>
                            <td align="Right">&nbsp;</td>
                            <td><a href="resetpw.php?visit=sRhvMItOu1hNV_y9t4iB7xhns2UJ0pUIYmpJyy3CivjvGYv0ST1QHY40QP9H5UPTqonadminkin_65dvtXxSIXDPwyFFI6WPVQFmgFtba8vW3OH" class=white>Forgot your password ?</a></td>
                          </tr>
                        </table>
                          <p>&nbsp;</p>
                      </td>
                    </tr>
                  </table>
                </form>

 

My function to perform the logon is:

 

Func StartUp()
   _IELinkClickByText ( $oIE, "Log On" )
   Sleep(2000)
   Local $oForm = _IEFormGetCollection($oIE)
   Local $iNumberOfForms = @extended

   For $iForm = 0 To $iNumberOfForms - 1
     $oForm = _IEFormGetCollection($oIE, $iForm)

     Local $oQuery = _IEFormElementGetCollection($oForm)

     Local $iNumberOfFormElements = @extended

     For $iElement = 0 to $iNumberOfFormElements - 1
         Local $oFormElement = _IEFormElementGetCollection($oForm, $iElement )
         If $oFormElement.name = 'user' Then
            _IEFormElementSetValue ( $oformElement, "xxxxx", 0)
         elseif $oFormElement.name = "pass" Then
            _IEFormElementSetValue ( $oFormElement, "yyyyy", 0)
            ; Sleep for 2 seconds.
            Sleep(2000)
            Local $oSubmit = _IEGetObjByName($oIE, "Submit")
            _IEAction($oSubmit, "click")
            Sleep(3000)
         EndIf
      Next
   Next
EndFunc

 


After the submission of the form completes and goes to the next page I'm getting the following error as a popup from AutoIt:

 


Line 970 (File "D\Program Files (x86)\AutoIt3\Include\IE.au3"):
Case $iIndex > -1 And $iIndex < $oObject.elements.length
Case $iIndex > -1 And $iIndex < $oObject^ ERROR
Error: The requested actions with this object has failed.


It's hard to imagine that such a simple form is causing so many problems.

Any help would be appreciated.

 

 

 

Link to comment
Share on other sites

That line number is located inside the function _IEFormElementGetCollection. Your code calls this function multiple times. Have you determined which call is generating the error?

I suspect it's the initial one, but can't tell from your post. Suggest that you add some error checking for each call to the IE functions.

Link to comment
Share on other sites

Thanks Danp2.

It was simply a dumb mistake.

I found that i submitted the form after filling in the 3'rd input element. This moved on to the next page.

But, the loop continued to examine the 4'th element which no longer existed.This caused the error.

So, I added an "Exitloop 2" statement after the final sleep which worked to get out of the two For loops.

Thanks again.

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

×
×
  • Create New...