Jump to content

IE.au3 form submit help


Recommended Posts

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

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>

 

Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

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

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

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

:)

#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:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor 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 * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

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 * SciTE - Lexer for console pane

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 * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

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 TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

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 *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"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: 2023-04-24

Link to comment
Share on other sites

  • 1 year later...

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