ice1000 Posted December 16, 2007 Share Posted December 16, 2007 I have a web form that I need to automate. Being new to AutoIt, I first used a simple recorder to click a button to move a GL Account down. Here's the script: Opt("WinWaitDelay",100) Opt("WinTitleMatchMode",4) Opt("WinDetectHiddenText",1) Opt("MouseCoordMode",0) WinWait("Planning: Account Administration","") If Not WinActive("Planning: Account Administration","") Then WinActivate("Planning: Account Administration",""); WinWaitActive("Planning: Account Administration","") For $i = 1 to 12 MouseClick("left",514,746,1) sleep(5000) next It works ok but I wanted to improve it. I came up with the following: Opt("WinWaitDelay",100) Opt("WinTitleMatchMode",4) Opt("WinDetectHiddenText",1) Opt("MouseCoordMode",0) #include <IE.au3> $MaxMoves = 4 If Not WinActive("Planning: Account Administration","") Then WinActivate("Planning: Account Administration",""); WinWaitActive("Planning: Account Administration","") ;Set reference to IE object $oIE = _IEAttach("Account Administration") ;Get reference to submit button $oSubmit = _IEGetObjByName ($oIE, "btnMoveDownAcct") ;Click button n times for $n = 1 to $MaxMoves If Not WinActive("Planning: Account Administration","") Then WinActivate("Planning: Account Administration",""); WinWaitActive("Planning: Account Administration","") _IEAction ($oSubmit, "click") _IELoadWait ($oIE) Sleep(5000) Next I made the action sleep for 5 seconds because it wouldn't work without it. The button click action executes a vbcript on the web page. The problem is that when I run my new code, the account gets moved once, then I get an error. C:\Program Files\AutoIt3\Include\IE.au3 (2697) : ==> The requested action with this object has failed.: $o_object.Click () $o_object.Click ()^ ERROR Can anyone tell me what I am missing here? Link to comment Share on other sites More sharing options...
FreeSiker Posted December 16, 2007 Share Posted December 16, 2007 (edited) Hi First off all, use the last version of autoit and use the html code to manange your script actions So if the html page hold this source <INPUT type="text" name="username" value="" maxLength="32" size="20" defaultFocus="true" > <input type="Submit" name="Submit" value="GO" class="buttonGroupBrand"> Your script should look like this ;create the webpage $oIE = _IECreate ("https://www.onlineaccess.ca", 1, 1, 1, 1) ;find the object in the page with the name "username" $o_user = _IEGetObjByName ($oIE, "username") _IEFormElementSetValue ($o_user, "user") ;find the object in the page with the name "submit" and click on it $o_submit = _IEGetObjByName ($oIE, "submit") _IEAction ($o_submit, "click") ;wait the end of loading _IELoadWait ($oIE)oÝ÷ ÙhØ^)Ùh¢IbëajÖ®¶sb6æ6ÇVFRfÇC´RæS2fwC° ¢b33c´ÖÖ÷fW2Ò £¶7&VFRFRvV'vP¢b33c¶ôRÒôT7&VFRgV÷C¶GG3¢ò÷wwrævöövÆRæ6öÒgV÷C²Â ¤Fð£¶fæBFRö&¦V7BâFRvRvFFRæÖRgV÷C·W6W&æÖRgV÷C°¢b33c¶õ÷W6W"ÒôTvWDö&¤'æÖRb33c¶ôRÂgV÷C·gV÷C²¢ôTf÷&ÔVÆVÖVçE6WEfÇVRb33c¶õ÷W6W"ÂgV÷C·FW7BgV÷C²¢¶fæBFRö&¦V7BâFRvRvFFRæÖRgV÷C·7V&ÖBgV÷C²æB6Æ6²öâ@¢b33c¶õ÷7V&ÖBÒôTvWDö&¤'æÖRb33c¶ôRÂgV÷C¶'FärgV÷C²¢ôT7Föâb33c¶õ÷7V&ÖBÂgV÷C¶6Æ6²gV÷C²¢ôTÆöEvBb33c¶ôR¢b33c´ÖÖ÷fW2Òb33c´ÖÖ÷fW2²¥VçFÂb33c´ÖÖ÷fW2Ò Edited December 16, 2007 by FreeSiker Link to comment Share on other sites More sharing options...
ice1000 Posted December 16, 2007 Author Share Posted December 16, 2007 Sorry I wasn't clearer in my initial post. The IE object already exists, that is why I am using _IEAttach vs _IECreate. I'm not sure what the difference is between FreeSiker's code and mine. We each use a slightly different loop but we each use _IEGetObjByName and _IEAction to get the object and perform an action. What's the difference? Why use _IEFormElementSetValue on a button? Link to comment Share on other sites More sharing options...
ice1000 Posted December 16, 2007 Author Share Posted December 16, 2007 I figured it out. Apparently the $oIE = _IEAttach("Account Administration") and $oSubmit = _IEGetObjByName ($oIE, "btnMoveDownAcct") are "lost" when the page reloads. If I put them inside the loop, it works as expected. Tricky! Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 17, 2007 Share Posted December 17, 2007 I figured it out. Apparently the$oIE = _IEAttach("Account Administration")and $oSubmit = _IEGetObjByName ($oIE, "btnMoveDownAcct")are "lost" when the page reloads. If I put them inside the loop, it works as expected. Tricky!Not quite. Your $oIE should still be valid after navigation, because it points to the browser instance, not the DOM (page) that currently loaded.The $oSubmit however is certainly lost because that object is part of DOM which get deleted and replaced with the new one by navigation.So, if the new page being loaded also has a object that can be referenced by name at "btnMoveDownAcct", you can get the the new $oSubmit with the same code, because $oIE is still valid. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
ice1000 Posted December 17, 2007 Author Share Posted December 17, 2007 Not quite. Your $oIE should still be valid after navigation, because it points to the browser instance, not the DOM (page) that currently loaded. The $oSubmit however is certainly lost because that object is part of DOM which get deleted and replaced with the new one by navigation. So, if the new page being loaded also has a object that can be referenced by name at "btnMoveDownAcct", you can get the the new $oSubmit with the same code, because $oIE is still valid. Thank you for the explanation. It makes sense. The $oIE is still valid and if I move that line outside the loop, the code continues to work. However, if I move the $oSubmit out of the loop, the code no longer works. The page being loaded is the same page, with the same controls, except that a grid control has a new order for the accounts. Regardless, it's working now. Here's the code in case it helps anyone else: Opt("WinWaitDelay",100) Opt("WinTitleMatchMode",4) Opt("WinDetectHiddenText",1) Opt("MouseCoordMode",0) #include <IE.au3> $MaxMoves = InputBox("Sort","Enter number of times to move Account down") $oIE = _IEAttach("Account Administration") ;Click button i times For $i = 1 to $MaxMoves If Not WinActive("Planning: Account Administration","") Then WinActivate("Planning: Account Administration",""); WinWaitActive("Planning: Account Administration","") $oSubmit = _IEGetObjByName ($oIE, "btnMoveDownAcct") _IEAction ($oSubmit, "click") _IELoadWait ($oIE) Next Link to comment Share on other sites More sharing options...
ur Posted August 17, 2017 Share Posted August 17, 2017 I have a button like below. <button tabindex="0" class="x-btn-text" style="width: 64px; position: relative;" type="button">Initialize</button> No id or name for it. How to click on that then? Link to comment Share on other sites More sharing options...
BrewManNH Posted August 17, 2017 Share Posted August 17, 2017 You need to open a new thread, this one is 10 years old! Why would you think it's a good idea to post something like this in a thread this old? Danp2 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator 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