NewPlaza Posted November 14, 2013 Posted November 14, 2013 Hello, I am tring to automate my login for a specific site and having much trouble interacting with the page. I have interacted with other webpages in the past but this one seems very nested and I can't seem to get it. I just want it to add my username/password on the available fields. Nothing more. Here's the page. Thanks. AcmeService.htm
Kidney Posted November 14, 2013 Posted November 14, 2013 you will need to get a hold of the handle of the form on the page. once you do that, you should then be able to access the input boxes for username and password
NewPlaza Posted November 14, 2013 Author Posted November 14, 2013 you will need to get a hold of the handle of the form on the page. once you do that, you should then be able to access the input boxes for username and password The handle? What do you mean by that. Sorry for my ignorance. I know almost nothing about HTML and DOM. In fact the many times I have interacted with webpages much came examples and such. Still learning.
Xenobiologist Posted November 14, 2013 Posted November 14, 2013 (edited) #include<IE.au3> $sUsername = "Username" $sPassword = "Password" $sUrl = "http://www.yourURL.com" $oIE = _IECreate($sUrl, 0, 1, 0, 1) Sleep(2000) $oHWND = _IEPropertyGet($oIE, "hwnd") WinSetState($oHWND, "", @SW_MAXIMIZE) $oForm = _IEFormGetCollection($oIE, 0) $oUsername = _IEFormElementGetObjByName($oForm, 'ID_LOGON_UserNameText') $oPassword = _IEFormElementGetObjByName($oForm, "ID_LOGON_PasswordText") _IEFormElementSetValue($oUsername, $sUsername) _IEFormElementSetValue($oPassword, $sPassword) _IEFormSubmit($oForm) Edited November 14, 2013 by Xenobiologist Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
NewPlaza Posted November 14, 2013 Author Posted November 14, 2013 @Xenobiologist Thanks but I can't seem to make it work. Anyhow I had to redo my code for the other sites because it would not add the login information if a second browser window was opened. This is what I came up with for the few others I have automated. If WinActive("Acme Site1") Then If StringInStr(WinGetText("[active]"), "Acme Site1 - Windows Internet Explorer") Then Local $hActiveWindow = WinGetHandle("[active]") Local $WindowList = WinList("Acme Site1") For $i = 1 To $WindowList[0][0] Local $oIE = _IEAttach("Acme Site1", "TITLE", $i) Local $hCurrentWindow = _IEPropertyGet($oIE, "HWND") If $hCurrentWindow = $hActiveWindow Then $oUserID = _IEGetObjByName($oIE, "login_id") $oUserID = _IEFormElementGetValue($oUserID) If Not $oUserID = "MyLoginName" Then $oUserID = _IEGetObjByName($oIE, "login_id") $oPassword = _IEGetObjByName($oIE, "login_id_password") _IEFormElementSetValue($oUserID, "MyLoginName") _IEFormElementSetValue($oPassword, "XxXxXxX") EndIf EndIf Next EndIf EndIf I just cant make this last site work..Any suggestions would be great.
Xenobiologist Posted November 14, 2013 Posted November 14, 2013 And what happens? Any errors? Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
NewPlaza Posted November 14, 2013 Author Posted November 14, 2013 I get dozens of warning from scite. --> IE.au3 V2.4-0 Warning from function _IEFormElementGetObjByName, $_IEStatus_NoMatch --> IE.au3 V2.4-0 Warning from function _IEFormElementGetObjByName, $_IEStatus_NoMatch --> IE.au3 V2.4-0 Error from function _IEFormElementSetValue, $_IEStatus_InvalidDataType
corgano Posted November 14, 2013 Posted November 14, 2013 The help file is brilliant! Go to SciTE, click a function name, and hit F1. It will show you the function in the help file, as well as an example. Another great tool is google chrome's inspect element (or on IE hit F12 and a similar tool pops up). You can have it highlight the element you want to fill in, and you can see in the HTML what it is called. Using this you can get the names of almost every element that exists, the forum, anything! If you plan to do any pattern matching / regexpwork, _IEBodyReadHTML() will show you exactly what IE sees, and http://gskinner.com/RegExr/ is AWESOME for making and testing RegEx statements. That and stringregexp() will make IE automation easy and CONSULT THE HELP FILE! It's amazingly helpful 0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e
alexstone Posted November 14, 2013 Posted November 14, 2013 Is it necessary to use script to make auto login? Maybe there is another way?
corgano Posted November 14, 2013 Posted November 14, 2013 log in manually! 0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e
NewPlaza Posted November 15, 2013 Author Posted November 15, 2013 log in manually! 812 posts and counting!!
NewPlaza Posted November 15, 2013 Author Posted November 15, 2013 Okay This seems to work with the attached HTM file. I'll know more next week if it will work on the 'live' site. If WinActive("acme") Then If StringInStr(WinGetText("[active]"), "acme - Windows Internet Explorer") Then Local $hActiveWindow = WinGetHandle("[active]") Local $WindowList = WinList("acme") For $i = 1 To $WindowList[0][0] Local $oIE = _IEAttach("acme", "TITLE", $i) Local $hCurrentWindow = _IEPropertyGet($oIE, "HWND") If $hCurrentWindow = $hActiveWindow Then Local $oForm = _IEFormGetCollection($oIE, 0) Local $oUserID = _IEFormElementGetObjByName($oForm, "ID_LOGON_UserNameText") $oUserID = _IEFormElementGetValue($oUserID) If Not $oUserID = "TestName" Then Local $oUserID = _IEFormElementGetObjByName($oForm, "ID_LOGON_UserNameText") Local $oPassword = _IEFormElementGetObjByName($oForm, "ID_LOGON_PasswordText") _IEFormElementSetValue($oUserID, "TestName") _IEFormElementSetValue($oPassword, "TestPassword") EndIf EndIf Next EndIf EndIf There are a few warnings with the above code but at lease its doing more then what it did before.
bogQ Posted November 15, 2013 Posted November 15, 2013 (edited) dumb question, but because of this code inside that htm file ---if(window.parent.document.getElementById("IFrame1"))---, isn't maybe that you're login is inside iframe when you try to get its elements? Edited November 15, 2013 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.
Xenobiologist Posted November 15, 2013 Posted November 15, 2013 Another way would be using a e.g. firefox plugin callled iMacros. That way it is so damn easy to automate a login. :-) Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
NewPlaza Posted November 15, 2013 Author Posted November 15, 2013 dumb question, but because of this code inside that htm file ---if(window.parent.document.getElementById("IFrame1"))---, isn't maybe that you're login is inside iframe when you try to get its elements? I have absolutly no idea. Another way would be using a e.g. firefox plugin callled iMacros. That way it is so damn easy to automate a login. :-) IE only.. ff not allowed..
Xenobiologist Posted November 15, 2013 Posted November 15, 2013 Give it a try : http://www.iopus.com/download/imacros-ie/ Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
corgano Posted November 15, 2013 Posted November 15, 2013 Query, what is the live site? If it is public, we could actually SEE what we're doing and make an account to try it out ourselves. It'd be much easier to help you 0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e
NewPlaza Posted November 18, 2013 Author Posted November 18, 2013 Query, what is the live site? If it is public, we could actually SEE what we're doing and make an account to try it out ourselves. It'd be much easier to help you It's a work intranet addy. Anyhow, I was not successful in automation this particular site.. bummer. Oh well.. 8 out of 9 is automated is good. @Xenobiologist Thanks for the link but that is to big to install on my workstation with no "real" justifiable reason. Thanks for eveybodys help here. I will just have to play with it some more. I'm sure I'll get it in time.
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