Georgio Posted October 27, 2011 Share Posted October 27, 2011 (edited) Hi all Weird problem. I have written an autoit script which does the following: 1. Open IE 2. Navigate to web URL 3. Login to site 4. select form values and submit 5. When the "File download" dialog appears, click save 6. When the "Save As" dialog appears, click OK to save to default location 7. Repeat steps 4 to 6 a number of times 8. Close IE The weird part is that although the script works perfectly the first time when run on a daily schedule, it gets stuck the second time around. It gets up to step 5 where the "File download" dialog appears, but it is unable to ControlClick the save button. If I use my mouse to focus the dialog, the script continues on its merry way. If I restart the server, it works again for 1 scheduled run only and fails on subsequent runs. Any ideas? expandcollapse popup#include <IE.au3> #include <GuiListView.au3> ;Set Default IE DL Directory RegWrite("HKEY_USERS\S-1-5-21-1202660629-602609370-xxxxxxxxx-51977\Software\Microsoft\Internet Explorer", "Download Directory", "REG_SZ", "C:\new downloads") ;Launch IE AdlibRegister("LoginLib") $oIE = _IECreate( "https://website.com/cgi-bin/broker?_service=UACrep&_program=gui.stdreplib.sas&statslib=os12") Sleep(2000) AdlibUnRegister("LoginLib") ;Prep attributes within IE, ; This section navigates multiple form pages setting default attributes, after this section we can simply modify populdated attributes. $oForm = _IEFormGetObjByName ($oIE, "form1") $oLibraryName = _IEFormElementGetObjByName ($oForm, "libname") _IEFormElementSetValue ($oLibraryName, "STATSLIB ") _IEFormSubmit ($oForm) $oDataSetValue = "APPLIC " $oForm = _IEFormGetObjByName ($oIE, "form1") $oDataSet = _IEFormElementGetObjByName ($oForm, "dataset") _IEFormElementSetValue ($oDataSet, $oDataSetValue) $oMonyyValue = "os12" $oMonyy = _IEFormElementGetObjByName ($oForm, "monyy") _IEFormElementSetValue ($oMonyy, $oMonyyValue) _IEFormSubmit ($oForm) $oForm = _IEFormGetObjByName ($oIE, "form1") $oExportType = _IEFormElementGetObjByName ($oForm, "StdRepSel") _IEFormElementSetValue ($oExportType, "reports.exportdata.sas") ;============================================================== $oMonyyValue = "os12" AdlibRegister("SaveLib1") AdlibRegister("SaveLib2") If $CmdLine[0] = 0 Then $oDataSetValue = "Value1" DefineDataSetValue () Sleep(100000) $oDataSetValue = "Value2" DefineDataSetValue () Sleep(100000) $oDataSetValue = "Value3" DefineDataSetValue () Sleep(100000) $oDataSetValue = "Value4" DefineDataSetValue () Sleep(100000) $oDataSetValue = "Value5" DefineDataSetValue () Sleep(100000) $oDataSetValue = "Value6" DefineDataSetValue () Sleep(100000) $oDataSetValue = "Value7" DefineDataSetValue () Sleep(100000) $oDataSetValue = "Value8" DefineDataSetValue () Sleep(100000) $oDataSetValue = "Value9" DefineDataSetValue () Sleep(100000) $oDataSetValue = "Value10" DefineDataSetValue () Sleep(100000) $oDataSetValue = "Value11" DefineDataSetValue () Sleep(100000) $oDataSetValue = "Value12" DefineDataSetValue () Sleep(100000) $oDataSetValue = "Value13" DefineDataSetValue () Sleep(100000) $oDataSetValue = "Value14" DefineDataSetValue () Sleep(100000) $oDataSetValue = "Value15" DefineDataSetValue () Sleep(100000) $oDataSetValue = "Value16" DefineDataSetValue () Sleep(100000) $oDataSetValue = "Value17" DefineDataSetValue () Sleep(100000) CloseIE() EndIf If $CmdLine[0] = 1 Then $oDataSetValue = $CmdLine[1] & " " DefineDataSetValue () CloseIE() EndIf AdlibUnRegister("SaveLib1") AdlibUnRegister("SaveLib2") Exit ; ===== General Functions ===== Func LoginLib() If WinExists("Connect to website.com") Then ControlSetText("Login dialog", "", "[CLASS:Edit; INSTANCE:2]", "username") ControlSetText("Login dialog", "", "[CLASS:Edit; INSTANCE:3]", "password") ControlClick("Login dialog", "", "[CLASS:Button; INSTANCE:2]") EndIf EndFunc Func SaveLib1() If WinExists("File Download") Then Sleep (2000) ControlClick("File Download", "", "[CLASS:Button; INSTANCE:2]") Sleep (2000) EndIf EndFunc Func SaveLib2() If WinExists("Save As") Then Sleep (2000) ControlClick("Save As", "", "[CLASS:Button; INSTANCE:1]") Sleep (2000) EndIf EndFunc Func DefineDataSetValue () $oForm = _IEFormGetObjByName ($oIE, "form1") $oDataSet = _IEFormElementGetObjByName ($oForm, "dataset") _IEFormElementSetValue ($oDataSet, $oDataSetValue) $oMonyy = _IEFormElementGetObjByName ($oForm, "monyy") _IEFormElementSetValue ($oMonyy, $oMonyyValue) _IEFormSubmit ($oForm) Sleep (9000) $oDataSetValue = "" EndFunc Func CloseIE() If WinExists("https://website.com/cgi-bin/broker - Windows Internet Explorer") Then WinClose("https://website.com/cgi-bin/broker - Windows Internet Explorer") EndIf EndFunc Edited October 27, 2011 by Georgio Link to comment Share on other sites More sharing options...
chachew Posted October 28, 2011 Share Posted October 28, 2011 Does the "Save As" popup have the same name every time it appears? Maybe ControlClick("Save As", "", "[CLASS:Button; INSTANCE:1]") instance changes Link to comment Share on other sites More sharing options...
Georgio Posted October 28, 2011 Author Share Posted October 28, 2011 I checked that, both "File download" and "Save As" always have the same instance numbers for the buttons and the same Titles. It's weird how restarting the machine always fixes it. I forgot to mention that I even tried scheduling a server restart using "shutdown.exe -r" before running autoit scripts. Still no luck. Only when I physically log in an restart it. I also forgot to mention that the user that runs the script is automatically logged in when the machine is started. That's why I'm always restarting it. Link to comment Share on other sites More sharing options...
chachew Posted October 28, 2011 Share Posted October 28, 2011 Is there an error code set with @error? 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