MirnesC2 Posted September 8, 2013 Share Posted September 8, 2013 This is the HTML pulled from the desired page.. expandcollapse popup<!-- BEGIN BODY --> <body class="login"> <!-- BEGIN LOGO --> <div class="logo"> <img src="assets/img/logo-big.png" alt="" /> </div> <!-- END LOGO --> <!-- BEGIN LOGIN --> <div class="content"> <!-- BEGIN LOGIN FORM --> <form class="form-vertical login-form" method="post"> <h3 class="form-title">Login to your account</h3> <div class="control-group"> <div class="controls"> <div class="input-icon left"> <i class="icon-user"></i> <input class="m-wrap" type="text" name="username" placeholder="Username" /> </div> </div> </div> <div class="control-group"> <div class="controls"> <div class="input-icon left"> <i class="icon-lock"></i> <input class="m-wrap" type="password" style="" name="password" placeholder="Password" /> </div> </div> </div> <div class="form-actions"> <label class="checkbox"> <input type='checkbox' name='rememberme'><A title='Saves your session for 48 hours' rel='tooltip-b' herf='#'>Remember me</a> </label> <input type="submit" id="login-btn" name="loginBtn" class="btn green pull-right" value="Login" /> </form> </div> <div class="forget-password"> <h4>Don't have an account ?</h4> <p> no worries, click <a href="javascript:;" class="" id="forget-password">here</a> to register an account. </p> </div> </form> <!-- END LOGIN FORM --> and this is my .au3 code expandcollapse popup#include <IE.au3> Local $oIE = _IECreate("http://www.website.net/",0,1,1,1) Local $sHTML = _IEBodyReadHTML($oIE) ;---> Finds login in forms and defines it to variable. $oForm = _IEFormGetObjByName($oIE, "form-vertical login-form") ;--->Reports error. Exit on error, else login. If $oForm = 0 Then MsgBox(48,"Error", "Error "&@error&" has occured handling the variable '$oForm'.") Exit Else ;--->Creates variables for input fields in targeted form above. $iUser = _IEFormElementGetObjByName($oForm, "username") $iPass = _IEFormElementGetObjByName($oForm, "password") ;--->Enters data into input fields of IE window. _IEFormElementSetValue($iUser, "john") _IEFormElementSetValue($iPass, "orange12") ;--->Submits form to server. _IEFormSubmit($oForm) EndIf I keep getting error 7 (7 ($_IEStatus_NoMatch) = No Match) which means it's not finding the form by what I put in I suppose.. what would I put for the login ID or NAME instead of "form-vertical login-form" which isn't working?? Link to comment Share on other sites More sharing options...
trancexx Posted September 8, 2013 Share Posted September 8, 2013 (edited) If the form doesn't have id or name specified, then you need to use the index of appearance. That would be _IEFormGetCollection() function.My another and better advice would be not to use IE.au3 at all for something like this. If I were you I would use Winhttp.au3, not because I wrote it, but because it's much more sensible solution:#include "WinHttp.au3" ; Initialize and get session handle $hOpen = _WinHttpOpen() ; Get connection handle $hConnect = _WinHttpConnect($hOpen, "www.website.net") ; web server where the site is hosted ; Fill the login form and collect resulting page $sHTML = _WinHttpSimpleFormFill($hConnect, _ Default, _ ; your code suggested default page "index:0", _ ; first form on the page has index 0, second is index 1, etc... You set correct one here, it's my assumption that it's 0 value "name:username", "John", _ ; <- filling username field by "name" attribute "name:password", "orange12") ; <- filling password field by "name" attribute ; ...Check @error here and maybe inspect value of $sHTML variable to see if login was successful ; After that you use $hConnect and $hOpen to automate further. Those handles will have cookies attached ; and every action you would do later with them will be from user "John" with password "orange12". ;... The rest of the code... ;... ; When you are done close handles _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) Edited September 8, 2013 by trancexx MirnesC2 1 ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
MirnesC2 Posted September 8, 2013 Author Share Posted September 8, 2013 If the form doesn't have id or name specified, then you need to use the index of appearance. That would be _IEFormGetCollection() function. My another and better advice would be not to use IE.au3 at all for something like this. If I were you I would use Winhttp.au3, not because I wrote it, but because it's much more sensible solution: #include "WinHttp.au3" ; Initialize and get session handle $hOpen = _WinHttpOpen() ; Get connection handle $hConnect = _WinHttpConnect($hOpen, "www.website.net") ; web server where the site is hosted ; Fill the login form and collect resulting page $sHTML = _WinHttpSimpleFormFill($hConnect, _ Default, _ ; your code suggested default page "index:0", _ ; first form on the page has index 0, second is index 1, etc... You set correct one here, it's my assumption that it's 0 value "name:username", "John", _ ; <- filling username field by "name" attribute "name:password", "orange12") ; <- filling password field by "name" attribute ; ...Check @error here and maybe inspect value of $sHTML variable to see if login was successful ; After that you use $hConnect and $hOpen to automate further. Those handles will have cookies attached ; and every action you would do later with them will be from user "John" with password "orange12". ;... The rest of the code... ;... ; When you are done close handles _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) Ah thank you! The IEFormGetCollection worked when finding it by index. But for some reason the submit function still isn't working. It's the correct username and password entered.. when i take out the submitform part and hit the button manually it works. But with the submit form it submits and just refreshes the page it seems.. no login failed, nothing.. it just resets the username and passwords. #include <IE.au3> Local $oIE = _IECreate("http://www.web.net/",0,1,1,1) Local $oForm = _IEFormGetCollection($oIE, 0) _IELoadWait($oIE) Local $oQuery = _IEFormElementGetCollection($oForm, 0) _IEFormElementSetValue($oQuery, "username") Local $oQuery = _IEFormElementGetCollection($oForm, 1) _IEFormElementSetValue($oQuery, "password") _IEFormSubmit($oForm) Link to comment Share on other sites More sharing options...
Valuater Posted September 8, 2013 Share Posted September 8, 2013 Maybe try this _IEAction($oForm, "click") 8) MirnesC2 1 Link to comment Share on other sites More sharing options...
MirnesC2 Posted September 8, 2013 Author Share Posted September 8, 2013 Maybe try this _IEAction($oForm, "click") 8) Still nothing, didn't even submit the form :3 Link to comment Share on other sites More sharing options...
Gianni Posted September 8, 2013 Share Posted September 8, 2013 Maybe try this Local $button = _IEFormElementGetObjByName($oForm, "loginBtn") _IEAction($button, "click") MirnesC2 and avidovi 2 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
MirnesC2 Posted September 8, 2013 Author Share Posted September 8, 2013 Maybe try this Local $button = _IEFormElementGetObjByName($oForm, "loginBtn") _IEAction($button, "click") Ahh yes that worked! Thank you!! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now