Maggotus Posted June 28, 2012 Share Posted June 28, 2012 Hey Everyone - I'm somewhat new to AutoIT and very new to using it to interact with IE. I'm working with a website where I cannot simulate a mouseclick on the login button. I've been searching the forums for a few days, and have tried every possibility that i can understand to do. I'm somewhat of a novice at scripting, but i do have a little experience. So far, the only method I've found to press 'Login' is to tab and send ENTER - but i know that's unreliable. When I've tried _IEAction($oLoginButton, "click") - it does nothing, but also doesn't return any error. I've also tried obtaining focus using _IEAction and sending ENTER, but that never appears to obtain focus. I even tried a copy/paste of code along these lines: $hwnd = _IEPropertyGet($oIE, "hwnd") ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}") but truthfully, i don't fully understand this method, and likely never appropriately massaged it for this page. I'm hoping someone can help me in the right direction. The credentials provided should throw an invalid login error - which would be great if I could even get it that far. Thanks in advance! #AutoIt3Wrapper_run_debug_mode=Y #include <IE.au3> ;~ Dim $sUsername = $CmdLine[1] ;~ Dim $sPassword = $CmdLine[2] ;~ Dim $sCompanyCode = $CmdLine[3] $sURL = "https://www.gotimeforce2.com/tfiiredirector" $sUsername = "test" $sPassword = "test" $sCompanyCode = "test" $oIE = _IECreate($sURL) WinSetState("[ACTIVE]", "", @SW_MAXIMIZE) $oForm = _IEFormGetCollection($oIE, 0) $oUsername = _IEFormElementGetObjByName($oForm, "usernamex") $oPassword = _IEFormElementGetObjByName($oForm, "passwordx") $oCompanyCode = _IEFormElementGetObjByName($oForm, "companycodex") $oLoginButton = _IEGetObjById($oIE,"submit") _IEFormElementSetValue($oUsername, $sUsername) _IEFormElementSetValue($oPassword, $sPassword) _IEFormElementSetValue($oCompanyCode, $sCompanyCode) Send("{TAB 9}") Send("{Enter}") _IELoadWait($oIE) Link to comment Share on other sites More sharing options...
MrMitchell Posted June 28, 2012 Share Posted June 28, 2012 Please read this thread... Link to comment Share on other sites More sharing options...
Maggotus Posted June 28, 2012 Author Share Posted June 28, 2012 Please read this thread...Hmm - i see your point. My problem isn't really the login process, it's the maintenance i have to do within our software once i get in, this just happens to be the only public page that others could see the source. I was going to assume that whatever methods i could use to press this button, could also be used to press the buttons that will allow me to run maintenance within the site.Is there another way to pose the question where it doesn't appear to violate the rules? Link to comment Share on other sites More sharing options...
MrMitchell Posted June 29, 2012 Share Posted June 29, 2012 After you manually log in are you having issues automating the rest of the site? I guess it just depends how the buttons are implemented...though if you are having a hard time with it, it might be because the site's designers intended to make it difficult to be automated Link to comment Share on other sites More sharing options...
Maggotus Posted June 29, 2012 Author Share Posted June 29, 2012 I'm only having trouble with the button clicks - everything else is fine. I'll rescind my earlier request for help with pushing the 'login' button - and I'm hoping someone can help me with clicking this new button.(I'm new to posting in this forum, and not sure whether this would warrant a new topic) <input type="button" id="RecalculateCompanyButton" class="ButtonBasic" value="GeneralForm.RecalculateEmployeeListText" onclick="recalCompany('63','This will remove all verifications for all employees during this pay period, and could take over 30 minutes to complete.\n\rAre you sure you wish to continue?')" /> Here is the code I am currently using to press the button: Send("+{TAB}") Sleep(500) Send("+{TAB}") Sleep(500) Send("+{TAB}") Sleep(500) Send("+{TAB}") Sleep(500) Send("+{TAB}") Sleep(500) Send("+{TAB}") Sleep(500) Send("{Enter}") Before when i tried to Send("+{TAB 6}") it wouldn't always land on the button. This method is very visible and takes a long time, and i'm still not confident in the results. I've also tried using the following: $oButton = _IEGetObjById ($oIE, "RecalculateCompanyButton") if @error = 0 Then msgbox(0,"",$oButton.value) EndIf _IEAction($oButton, "click") And this actually pops up the msgbox with the label of the button (which makes me think i've got the right object) - but alas, it still doesn't actually click the button. Using a similar method, I tried using the "focus" action, then sending ENTER, and got the same results. As to whether the developers made it difficult to automate - it is possible, but I don't think so. They were the ones that approached me to create a band-aid for a client while a permanent solution goes through the long haul of the development queue. I really appreciate help anybody could provide. Link to comment Share on other sites More sharing options...
MrMitchell Posted June 29, 2012 Share Posted June 29, 2012 It looks like you have to click the "recalculate" button then click yes in a confirmation message? Link to comment Share on other sites More sharing options...
Maggotus Posted June 29, 2012 Author Share Posted June 29, 2012 It looks like you have to click the "recalculate" button then click yes in a confirmation message?Yes - but the confirmation box doesn't even pop up when I use the above methods. Link to comment Share on other sites More sharing options...
jdelaney Posted June 29, 2012 Share Posted June 29, 2012 please don't automate using tabs ...use the _ie.* functions. 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. Link to comment Share on other sites More sharing options...
MrMitchell Posted June 29, 2012 Share Posted June 29, 2012 please don't automate using tabs ...use the _ie.* functions.If you read the whole thread you'd know he's currently using that method now but trying to get away from it... Link to comment Share on other sites More sharing options...
jdelaney Posted June 29, 2012 Share Posted June 29, 2012 One unproductive post to point out another, nice. anywho- Would you post the HTML of the button, and all it's sub elements? Sometimes, you must focus on a lower level than the actual <button> it's self. 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. Link to comment Share on other sites More sharing options...
MrMitchell Posted June 29, 2012 Share Posted June 29, 2012 (edited) @jdelaney - My apologies. As for original issue, I looked at it again and figure OP must be getting the correct object, and actually clicking the button but it's not firing the javascript. This function "recalCompany" would be Javascript, correct? Does this work? (you mentioned it but didn't provide exact code you used): $hWinIE = _IEPropertyGet($oIE, "hwnd") $oButton = _IEGetObjById ($oIE, "RecalculateCompanyButton") _IEAction($oButton, "focus") ControlSend($hWinIE, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}") Maybe also try ControlSend without specifying ControlID? Edited June 29, 2012 by MrMitchell Link to comment Share on other sites More sharing options...
Maggotus Posted June 30, 2012 Author Share Posted June 30, 2012 (edited) @MrMitchell -Tried what you provided, and still got no results. i also changed the last line of code toControlSend($hWinIE, "", "", "{Enter}")to see if it would make a difference and still nothing. There is no visible change when I use the_IEAction($oButton, "focus")command - shouldn't there be a visual cue that the button has obtained focus - similar to when you tab to the button? Also, yes - it appears to be Javascript - but i'm no developer, just a project manager with some experience with scripting and automating. Also - @jdelaney I'm not very experienced with HTML and don't know how to find whether a button has "sub elements". If you could point me in a direction that will tell me how to discover the sub elements, I'd be more than happy to provide. I'm not comfortable with posting the entire HTML of this particular page, but I will provide whatever will help if i can peel out the right pieces. More than likely this button has the same basic structure as the button found on the main http://www.gotimeforce2.com web page. That may provide us with some insight on what i could be missing here. Edited June 30, 2012 by Maggotus Link to comment Share on other sites More sharing options...
Maggotus Posted June 30, 2012 Author Share Posted June 30, 2012 I found this in the source - may confirm that the button triggers a javascript event? <script src="../JavaScript/RecalculateCompany.js" type="text/javascript"></script> The button <input type="button" id="RecalculateCompanyButton" class="ButtonBasic" value="GeneralForm.RecalculateEmployeeListText" onclick="recalCompany('63','This will remove all verifications for all employees during this pay period, and could take over 30 minutes to complete.\n\rAre you sure you wish to continue?')" /> appears to call this command(?): function CreateCommand(id, elementId){ switch(id){ case '63': var command = new Ajax.Commands.RecalculateCompany(elementId,id,counter); net.Base.addCommand(command); } The only other items i found in the source relating to recalculate company was a progress bar, and didn't seem to be helpful. Link to comment Share on other sites More sharing options...
MrMitchell Posted July 1, 2012 Share Posted July 1, 2012 (edited) It's a long shot but try using this in place of where you would click the button. $oIE.document.parentWindow.execScript("recalCompany('63','This will remove all verifications for all employees during this pay period, and could take over 30 minutes to complete. Are you sure you wish to continue?')","javascript") I've seen this method before but I am having trouble finding documentation for how to use it fully. Edited July 1, 2012 by MrMitchell Link to comment Share on other sites More sharing options...
Maggotus Posted July 14, 2012 Author Share Posted July 14, 2012 So, the good news is that your method appears partially to do what I need it to, and pops up the dialog box. The downside is that the script halts execution until i manually click OK or Cancel. I've tried using AdLibRegister- but that doesn't appear to fire when this is used... it appears that even it is halted after calling the command. Due to the fact that AutoIt is not multi-threaded, i'm not sure how i can proceed with this method. Link to comment Share on other sites More sharing options...
Maffe811 Posted July 14, 2012 Share Posted July 14, 2012 Uhm...Unless you didn't scroll:thanhphuc,Welcome to the AutoIt forum. Unfortunately you appear to have missed the Forum Rules on your way in. Please read them now - particularly the bit about not discussing login methods - and then you will understand why this thread will now be locked. See you soon with some legitimate codeI hope. M23 [font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler] Link to comment Share on other sites More sharing options...
Maggotus Posted July 14, 2012 Author Share Posted July 14, 2012 Uhm...Unless you didn't scroll:I think you probably just didn't read the whole thread. My problem is deeper, and is no longer directed at the login screen. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 14, 2012 Moderators Share Posted July 14, 2012 Maggotus, I agree you have moved on and I am happy for the thread to continue. M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
Maffe811 Posted July 15, 2012 Share Posted July 15, 2012 I think you probably just didn't read the whole thread. My problem is deeper, and is no longer directed at the login screen.No i didn't, i just asumed you were still trying to login so didn't read it.Sorry about that. [font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler] Link to comment Share on other sites More sharing options...
MrMitchell Posted July 15, 2012 Share Posted July 15, 2012 So, the good news is that your method appears partially to do what I need it to, and pops up the dialog box. The downside is that the script halts execution until i manually click OK or Cancel.I've tried using AdLibRegister- but that doesn't appear to fire when this is used... it appears that even it is halted after calling the command. Due to the fact that AutoIt is not multi-threaded, i'm not sure how i can proceed with this method.Can you look in the site's js file for the recalComany function and find out how to call it with an option to bypass confirmation dialog and just tell it to proceed without further user interaction? Right now you're calling it with two parameters but I only put that because that's what in the example you provided. Maybe if you adjust that '63' to another flag it might work...I dunno. Need that code! 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