Jump to content
berkan

IE.au3 form submit help

Recommended Posts

berkan

How would I use any of these methods:

_IEFormElementGetCollection()_IEFormElementGetObjByName()_IEFormGetCollection()_IEFormGetObjByName()

  to find this form submit with no name or ID?

<button class="button primary" tabindex="11" type="submit">Log In</button>

 

or is there another function I could use that's more suitable for this job? could I direct autoit to find the div and immediately look for a submit button within the div?

<div id="login_div" style>

 

This is what I've got so far, but the submit doesn't work correctly:

 

#include <IE.au3>

$sUsername = "testaccount"
$sPassword = "password"
Local $oIE = _IECreate("https://url.com/login")
Local $oSubmitU = _IEGetObjById($oIE, "login_user_login")
_IEFormElementSetValue($oSubmitU, $sUsername)
Local $oSubmitP = _IEGetObjById($oIE, "password")
_IEFormElementSetValue($oSubmitP, $sPassword)
Local $oLogin = _IEFormElementGetObjByName($oIE,"What can I do to find the submit?")
_IEAction($oLogin, "click")
Edited by berkan

Share this post


Link to post
Share on other sites
berkan

This is the entire form if anyone wants to take a look

<form accept-charset="UTF-8" action="https://url.com/login" class="js-login-form login_form " method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="Nn2IO3S8bWCEACZBHbwomPfTrrWTx840bQUiGfT8sos=" /></div>
<input id="redirect_on_login" name="redirect_on_login" type="hidden" value="https://url.com/login/" />
<input id="embed_form" name="embed_form" type="hidden" value="false" />
<input id="mp_source_action" name="mp_source_action" type="hidden" value="" />
<input id="follow" name="follow" type="hidden" value="" />
<div class='field item'>
<label class='label'>Username</label>
<input autofocus="autofocus" class="field text med-long" id="login_user_login" name="login" type="text" />
</div>
<div class='field item'>
<label class='label'>Password</label>
<input class="field text med-long" id="password" name="password" type="password" value="" />
<div class='help sub'>
<a href="https://url.com/reset_pw" class="small" id="trouble_link" rel="nofollow" style="margin-left: 0;">Trouble signing in?</a>
</div>
</div>
<div class='buttons'>
<button class="button primary" tabindex="11" type="submit">Log In
</button></div>
<img class="js-loading-spinner spinner" src="/images/spinner.gif" style="display:none" />
</form>

 

Share this post


Link to post
Share on other sites
Danp2

Look at the example code for _IEFormGetCollection. If the page is simple, then you can just reference the form by index. Beyond that, you are hiding the actual URL so I'm not inclined to help further. :think:

Share this post


Link to post
Share on other sites
berkan

Ah, had I known it was offensive, I wouldn't have censored anything.

https://secure.twitch.tv/login

<div id="login_div" style="">
<form accept-charset="UTF-8" action="https://secure-login.twitch.tv/login" class="js-login-form login_form " method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"><input name="authenticity_token" type="hidden" value="Nn2IO3S8bWCEACZBHbwomPfTrrWTx840bQUiGfT8sos="></div>
<input id="redirect_on_login" name="redirect_on_login" type="hidden" value="http://www.twitch.tv/">
<input id="embed_form" name="embed_form" type="hidden" value="false">
<input id="mp_source_action" name="mp_source_action" type="hidden" value="">
<input id="follow" name="follow" type="hidden" value="">
<div class="field item">
<label class="label">Username</label>
<input autofocus="autofocus" class="field text med-long" id="login_user_login" name="login" type="text" value="">
</div>
<div class="field item">
<label class="label">Password</label>
<input class="field text med-long" id="password" name="password" type="password" value="">
<div class="help sub">
<a href="https://secure.twitch.tv/user/reset_password" class="small" id="trouble_link" rel="nofollow" style="margin-left: 0;">Trouble signing in?</a>
</div>
</div>
<div class="buttons">
<button class="button primary" tabindex="11" type="submit">Log In
</button></div>
<img class="js-loading-spinner spinner" src="/images/spinner.gif" style="display:none">
</form>


</div>

What method can I use to click that button?

Edited by berkan

Share this post


Link to post
Share on other sites
berkan

That worked in the sense that it clicks the submit button, but it gives me this error right after the click.

 

This is the code so far:

#include <IE.au3>

$sUsername = "username"
$sPassword = "password"
Local $oIE = _IECreate("http://www.twitch.tv/")
Sleep (2000)
Local $oSubmit = _IEGetObjById($oIE, "header_login")
Sleep (2000)
_IEAction($oSubmit, "click")
Sleep (2000)
_IELoadWait($oIE)

Local $oSubmitU = _IEGetObjById($oIE, "login_user_login")
_IEFormElementSetValue($oSubmitU, $sUsername)
Local $oSubmitP = _IEGetObjById($oIE, "password")
_IEFormElementSetValue($oSubmitP, $sPassword)
Local $oLogin = _IEFormGetCollection($oIE, 1)
_IEFormSubmit($oLogin, 1)

 

error.jpg

Share this post


Link to post
Share on other sites
berkan

same error. any idea what could be causing it?

Okay, so, there are actually 2 forms in the source. Can you help me specify the script finds the right form? I believe my error will go away when it detects the specific form and not both.

Edited by berkan

Share this post


Link to post
Share on other sites
Shane0000

Does other form controls work as expected? like _IEFormReset()  Are you sure you have the right instance?

 

also when you run this through the editor you can add the line (right after the submit call)

If @error then consolewrite("Error: " & @error & @tab & "Extended: " &  @extended & @crlf)

this will give you more info on the error that ypu can look up  in the help file

 

Edited by Shane0000
@error

Share this post


Link to post
Share on other sites
berkan

I added formreset and it reset the form as expected. It also still gives the same error prompt.

#include <IE.au3>

$sUsername = "account"
$sPassword = "password"
Local $oIE = _IECreate("http://www.twitch.tv/")
Sleep (2000)
Local $oSubmit = _IEGetObjById($oIE, "header_login")
Sleep (2000)
_IEAction($oSubmit, "click")
Sleep (2000)
_IELoadWait($oIE)

Local $oSubmitU = _IEGetObjById($oIE, "login_user_login")
_IEFormElementSetValue($oSubmitU, $sUsername)
Local $oSubmitP = _IEGetObjById($oIE, "password")
_IEFormElementSetValue($oSubmitP, $sPassword)
Local $oLogin = _IEFormGetCollection($oIE, "card js-has-captcha")
_IEFormReset($oLogin)
_IEFormSubmit($oLogin, 1)

Local $oLogin = _IEFormGetCollection($oIE, "card js-has-captcha")

also submits the form, but errors.

Edited by berkan

Share this post


Link to post
Share on other sites
mLipok

:)

#include <IE.au3>

$sUsername = "username"
$sPassword = "password"
Local $oIE = _IECreate("http://www.twitch.tv/")
Sleep (2000)
Local $oSubmit = _IEGetObjById($oIE, "header_login")
Sleep (2000)
_IEAction($oSubmit, "click")
Sleep (2000)
_IELoadWait($oIE)

Local $oSubmitU = _IEGetObjById($oIE, "login_user_login")
_IEFormElementSetValue($oSubmitU, $sUsername)
Local $oSubmitP = _IEGetObjById($oIE, "password")
_IEFormElementSetValue($oSubmitP, $sPassword)
Local $oButtons = _IETagNameGetCollection($oIE,'button',-1)

For $oButton in $oButtons
    ConsoleWrite($oButton.outerHTML & @CRLF)
    If StringInStr($oButton.outerHTML,'<button tabindex="11" class="button primary" type="submit">') Then _IEAction($oButton,'click')
Next

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library
 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-10-31

Share this post


Link to post
Share on other sites
berkan

That worked. outerhtml parse was a good method. thank you, sir.

Share this post


Link to post
Share on other sites
KimberlyJillPereira

Try

 Local $oForm = _IEFormGetCollection($oIE, 0)

 _IEFormSubmit($oForm).

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

×