Suki

Unable to click submit button

13 posts in this topic

Hi,

I am not able to clock the submit button , text enclosed in black box in attachment. This has no  name or id. While trying to solve this I saw that I was unable to get the form name (loginform) as well.

Code for form fetch:

Local $oForms = _IEFormGetCollection($oIE)
Local $iNumForms = @extended
MsgBox($MB_SYSTEMMODAL, "Forms Info", "There are " & $iNumForms & " forms on this page")
Local $oForm
For $i = 0 To $iNumForms - 1
    $oForm = _IEFormGetCollection($oIE,1)
    MsgBox($MB_SYSTEMMODAL, "Form Info", $oForm.name)
Next

This shows me the number of forms correctly, ref. first message box but when it enters the for loop it does not print any form name under $oForm.name

Code to click on the submit button :

 

local $oTDs = $oIE.document.GetElementsByTagName($oIE, "input")
For $oTD in $oTDs
    If String(_IEPropertyGet($oTD, "innertext")) = "Sign in " Then
        Send("{Enter}")
        ExitLoop
    EndIf
Next

Nothing happens

PS - IF I JUST DO A SEND the website throws an error message stating invalid username or password.

submit.jpg

Share this post


Link to post
Share on other sites



Hi Subz thanks this works but i am facing the same issue as earlier. When i just did a send<enter> earier (and now i click on the button) the website throws an error invalid username or password. Is this related to the website security? If so , how to get around this? This is an intranet site so i can change the security settings if needed...

Share this post


Link to post
Share on other sites

Are you 100% sure the username and password are correct?  I'm assuming you're sending this information to the form?  Can you please confirm and if yes can you post an example of the code?

Share this post


Link to post
Share on other sites

Call ("login")

func login ()

#RequireAdmin
Global $oIE=_IECreate("http://localhost:8001/en-US/")

Local $username=_IEGetObjByName($oIE,"username")
local $password=_IEGetObjByName($oIE,"password")

   _IEFormElementSetValue($username,"admin")
   sleep (30000)
   Send("{TAB}")
   _IEFormElementSetValue($password,"Stalin1945")
   sleep (30000)
   send ("{TAB}")

 Local $oButtons = _IETagNameGetCollection($oIE, "Input")
For $oButton In $oButtons
    If $oButton.value = 'Sign in' Then  MsgBox(64, 'Button Found', 'Button found with value: ' & $oButton.value)
    ;_IEAction($oButton, 'click')
Next

I could log in to several other websites and also do operations inside the website but this one always gives the same issues

see attached screen shot as well

for some reason it is going inside the account log in error class

scrnshot.jpg

Share this post


Link to post
Share on other sites

Can you try:

#include <IE.au3>

Local $oIE = _IECreate("http://localhost:8001/en-US/", 1)
While _IEPropertyGet($oIE, "Busy")
    Sleep(100)
WEnd
Local $oForm = _IEFormGetObjByName($oIE, "loginForm")
Local $oUserName = _IEFormElementGetObjByName($oForm, "UserName")
_IEFormElementSetValue($oUserName, "Domain\UserName")
Local $oPassword = _IEFormElementGetObjByName($oForm, "Password")
_IEFormElementSetValue($oPassword, "Password")
_IEFormSubmit($oForm)

 

Share this post


Link to post
Share on other sites
17 hours ago, Suki said:

While trying to solve this I saw that I was unable to get the form name (loginform) as well.

This section of code is wrong --

For $i = 0 To $iNumForms - 1
    $oForm = _IEFormGetCollection($oIE,1)
    MsgBox($MB_SYSTEMMODAL, "Form Info", $oForm.name)
Next

The call to _IEFormGetCollection should be using $i, not a constant of 1.

Share this post


Link to post
Share on other sites

@subz - no , not working.

@dan0 - Yes you are right, I was testing and made a mistake, anyway no reason this should not return any value.

there are 2 forms on this page , putting $i should return both the forms in the for loop or putting 0 or 1 should return the first and second form names respectively,

This while code on fetching form names from auto it does not work, see example from the autoit help menu

Local $oIE = _IECreate("http://www.autoitscript.com")
Local $oForms = _IEFormGetCollection($oIE)
MsgBox($MB_SYSTEMMODAL, "Forms Info", "There are " & @extended & " form(s) on this page")
For $oForm In $oForms
    MsgBox($MB_SYSTEMMODAL, "Form Info", $oForm.name)
Next

 

This should return the form name on autoitscript.com page , right?

well it does not, attaching screen shot form name is always blank. If the autoit example code on the autoitscript page is failing what hope do I have :)?

autoit scrn shot.jpg

Share this post


Link to post
Share on other sites

If you check the source, the form has no defined name. ;-)

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Can you try:

#include <IE.au3>

Local $oIE = _IECreate("http://localhost:8001/en-US/", 1)
While _IEPropertyGet($oIE, "Busy")
    Sleep(100)
WEnd
Local $bForm = False
Local $oForms = _IETagNameGetCollection($oIE, "form")
Local $oInputs = _IETagNameGetCollection($oIE, "input")
For $oForm In $oForms
    If $bForm = True Then Exitloop
    If $oForm.ClassName = "loginForm" Then
        For $oInput In $oInputs
            If $oInput.GetAttribute("Data-Name") = "username" Then $oInput.value = "admin"
            If $oInput.GetAttribute("Data-Name") = "password" Then $oInput.value = "Stalin1945"
            If $oInput.value = 'Sign in' Then
                MsgBox(64, 'Input Found', 'Input found with value: ' & $oInput.value)
                _IEAction($oInput, 'click')
                $bForm = True
                Exitloop
            EndIf
        Next
    EndIf
Next

 

Edited by Subz
Added $bForm

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Many login pages now require a send to 'validate' the data (example...you set the value, but the button doesn't enable until you actually send a character at user/password inputs)...So doing a focus action, and then controlsend at the browser will fill in the data.

You can also look at my sig to grab elements by xpath.

Edited by jdelaney

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

#12 ·  Posted

ha well..i had a discussion on this particular thing with my web developer. There is a setting which detects insecure logins in the web config file, that had to be turned off..after that it works.many thanks for helping me out. I am not sure though how I will manage to run it for multiple users , currently I am in discussion with the users to either turn off the insecure log in settings or have a manual log in. There are operations inside the url that is more important to automate and I am working on that, Once again many thanks to Dan, Subz and jdelaney

Share this post


Link to post
Share on other sites

#13 ·  Posted

how did you turn off the insecure login plz,,

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