Jump to content

$oButton.Type not working as expected.


bluefish
 Share

Recommended Posts

Hello,

I'm trying to automate the login to my website, the code below will enter the username/password but login button does not appear to work, it looks like its pressed but nothing happens.

The html for the button is:

<input name="ctl00$MainContent$btnLogin" value="Login" id="ctl00_MainContent_btnLogin" class="button" type="submit">

Any ideas why it does not complete the login?

Thanks.

#include <IE.au3>

$Url = 'https://www.XXXXX.XX'
$User = 'XXXXXXX'
$Pwd = 'XXXXXXX'

$test = _IEAutoLogin($Url, $User, $Pwd)

Func _IEAutoLogin($sUrl, $sUsername, $sPwd)
 ;funkey 09.09.09
 $oIE = _IECreate($sUrl)
 _IEErrorNotify(False)
 $oForms = _IEFormGetCollection($oIE)
 If @error Then
  Return SetError(1, _IEErrorHandlerDeRegister(), $oIE) ;'no forms --> no login'
 Else
  $Index = 0
  For $oForm In $oForms
   $oFormElements = _IEFormElementGetCollection($oForm)
   If IsObj($oFormElements) Then
    $IndexElement = 0
    For $oElement In $oFormElements
     If $oElement.Type = 'password' Then
      $oPwd = _IEFormElementGetObjByName($oForm, $oElement.Name)
      _IEFormElementSetValue($oPwd, $sPwd)
      For $i = $IndexElement - 1 To 0 Step -1
       $oUser = _IEFormElementGetCollection($oForm, $i)
       If $oUser.Type = 'text' Then
        _IEFormElementSetValue($oUser, $sUsername)
        ExitLoop
       EndIf
      Next
      If $oForm.action <> "0" And Not StringInStr($oForm.action, '.php') Then  ;submit
       _IEFormSubmit($oForm, 0)
       _IELoadWait($oIE)
      Else  ;click
       For $i = $IndexElement + 1 To $IndexElement + 10 ;check the next 10 elements
        $oButton = _IEFormElementGetCollection($oForm, $i)
        If $oButton.Type = 'submit' Then
         _IEAction($oButton, "click")
         ExitLoop
        EndIf
       Next
      EndIf
     EndIf
     $IndexElement += 1
    Next
   EndIf
   $Index += 1
  Next
 EndIf
EndFunc   ;==>_IEAutoLogin
Link to comment
Share on other sites

Instead of using _IEFormSubmit try using:

_IEAction

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

 

Instead of using _IEFormSubmit try using:

_IEAction

Still seems to be the same except the password remains in the box but no login, my code is now:

#include <IE.au3>

$Url = 'https://www.XXXXXX.XXXX'
$User = 'XXXXX'
$Pwd = 'XXXXXX'

$test = _IEAutoLogin($Url, $User, $Pwd)

Func _IEAutoLogin($sUrl, $sUsername, $sPwd)
 ;funkey 09.09.09
 $oIE = _IECreate($sUrl)
 _IEErrorNotify(False)
 $oForms = _IEFormGetCollection($oIE)
 If @error Then
  Return SetError(1, _IEErrorHandlerDeRegister(), $oIE) ;'no forms --> no login'
 Else
  $Index = 0
  For $oForm In $oForms
   $oFormElements = _IEFormElementGetCollection($oForm)
   If IsObj($oFormElements) Then
    $IndexElement = 0
    For $oElement In $oFormElements
     If $oElement.Type = 'password' Then
      $oPwd = _IEFormElementGetObjByName($oForm, $oElement.Name)
      _IEFormElementSetValue($oPwd, $sPwd)
      For $i = $IndexElement - 1 To 0 Step -1
       $oUser = _IEFormElementGetCollection($oForm, $i)
       If $oUser.Type = 'text' Then
        _IEFormElementSetValue($oUser, $sUsername)
        ExitLoop
       EndIf
      Next
      If $oForm.action <> "0" And Not StringInStr($oForm.action, '.php') Then  ;submit
       _IEAction($oForm, 0)
       _IELoadWait($oIE)
      Else  ;click
       For $i = $IndexElement + 1 To $IndexElement + 10 ;check the next 10 elements
        $oButton = _IEFormElementGetCollection($oForm, $i)
        If $oButton.Type = 'submit' Then
         _IEAction($oButton, "click")
         ExitLoop
        EndIf
       Next
      EndIf
     EndIf
     $IndexElement += 1
    Next
   EndIf
   $Index += 1
  Next
 EndIf
EndFunc   ;==>_IEAutoLogin
Edited by bluefish
Link to comment
Share on other sites

Have a look at jdelaney's >IEbyXPATH UDF and see if that could potentially get everything straightened out for you.

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

JohnOne is correct, it should be _IEAction($oForm, "click").

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

  • Moderators

Something that caught my attention... You have

_IEAction($oForm, 0)
What is the "0" for exactly?

 

Also... you aren't providing anything for us to to test (url wise).  This just leads to long threads filled with guesses that could be solved in 1 or 2 posts normally.  I know I know, it's super top secret spy stuff, I get it... So my guess for the thread: indexes start at zero, you have: $IndexElement + 1 (can never be zero).  More than that there's no error checking or consolewrites to see what values you're actually getting.  Doesn't the submit button have an id/class/name etc?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Thanks for the help so far, I changed the

_IEAction($oForm, 0)

to be:

_IEAction($oForm, "click")

but its no different.

It's not super spy stuff :) the URL is https://www.westgateleisure.chichester.gov.uk/Connect2/mrmlogin.aspx

The submit button is <input name="ctl00$MainContent$btnLogin" value="Login" id="ctl00_MainContent_btnLogin" class="button" type="submit">

The ultimate aim is to:

1. Login to the site with my username / pass

2. Click a booking URL

3. Click 3 buttons, one after the other

Thanks.

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...