Robobobatron Posted March 23, 2017 Share Posted March 23, 2017 i am writing a script in which i am trying to automate a process of scraping information from a website. my process works flawlessly when i prompt the user for input regarding when the data is pulled from\ saved at. however, when i try to set all this information statically (in hopes of having a user free version) i get a crash. here is the funny thing though, it gets through several iterations of the code and then crashes. Functional code: expandcollapse popupLocal $oExcel = _Excel_Open(False) Local $oWorkbook = _Excel_BookOpen($oExcel, FileOpenDialog("Please choose the ID source", @HomePath, "All (*.*)"), True, False) Local $aResult = _Excel_RangeRead($oWorkbook, Default, $oWorkbook.ActiveSheet.Usedrange.Columns("A:A")) _Excel_Close($oExcel, false, true) ;make storage location $newPath = FileSelectFolder("Target Data location", $defaultLocal) if(FileExists($newPath)) then DirCreate($newPath&"\Agreements\") DirCreate($newPath&"\Receipts\") DirCreate($newPath&"\ScreenShots\") endif ;create instance of IE and maximize window $IE = _IECreate("https://wnlisvc1.whynotleaseit.com/ccm/login.aspx") local $hWnd = winwaitactive("CRM Collection Portal Home Page - Internet Explorer","",2) winsetstate($hWnd, "", @SW_MAXIMIZE) ;Do login _IEFormElementSetValue(_IEGetObjByName($IE, "ctl00$ContentPlaceHolder1$txtUserName"), $username) _IEFormElementSetValue(_IEGetObjByName($IE, "ctl00$ContentPlaceHolder1$txtPassword"), $password) _IEaction(_IEGetObjByName($IE, "ctl00$ContentPlaceHolder1$btnLogIn"), "click") sleep(1000) ;do primary looping logic for $cell in $aResult doSearch($cell) _IEaction(_IEGetObjByName($IE, "ctl00$ContentPlaceHolder1$btnOK"), "click") _IEaction(_IEGetObjByName($IE, "ctl00$ContentPlaceHolder1$btnMultiple"), "click") _IEaction(_IEGetObjByName($IE, "ctl00$ContentPlaceHolder1$btnLeasedItems"), "click") sleep(500) $check = _IELinkClickByText($IE, "View Agreement") ;this is to prevent a crash that was occouring when a invalid ID was put in and the script had nothing to click. if(not $check <= 0)then winwaitactive("TEMPOE | Document Renderer - Internet Explorer","",2) doPDFPrint($newPath&"\Agreements\", $cell) send("^w") winwaitactive("CRM Collection Portal Home Page - Internet Explorer","",2) $validationString = $validationString&$cell&" success"&@lf Else ConsoleWrite("Click Failed") _ScreenCapture_Capture($newPath&"\Agreements\"&$cell&".jpg", (@DesktopWidth/2)-5, (@DesktopHeight/2)-5, (@DesktopWidth/2)+5, (@DesktopHeight/2)+5, False) $validationString = $validationString&$cell&" fail"&@lf endif $check = _IELinkClickByText($IE, "View Receipt") ;this is to prevent a crash that was occouring when a invalid ID was put in and the script had nothing to click. if(not $check <= 0)then winwaitactive("TEMPOE | Document Renderer - Internet Explorer","",2) doPDFPrint($newPath&"\Receipts\", $cell) send("^w") winwaitactive("CRM Collection Portal Home Page - Internet Explorer","",2) Else ConsoleWrite("Click Failed") _ScreenCapture_Capture($newPath&"\Receipts\"&$cell&".jpg", (@DesktopWidth/2)-5, (@DesktopHeight/2)-5, (@DesktopWidth/2)+5, (@DesktopHeight/2)+5, False) endif _ScreenCapture_Capture($newPath&"\ScreenShots\"&$cell&".jpg", (@DesktopWidth/2)-400, (@DesktopHeight/2)-200, (@DesktopWidth/2)+380, (@DesktopHeight/2)+200, False) ;_IEaction(_IEGetObjByName($IE, "ctl00$ContentPlaceHolder1$btnCancel13"), "click") _IEaction(_IEGetObjByName($IE, "ctl00$ContentPlaceHolder1$btnNewSearch"), "click") sleep(2000) next _IEQuit($IE) Run("notepad") WinWaitActive("Untitled - Notepad") send($validationString) exit non functional code: expandcollapse popupLocal $oExcel = _Excel_Open(False) sleep(2000) ;$excelPath = FileOpenDialog("Please choose the ID source", @ScriptDir, "All (*.*)") $excelPath = @ScriptDir&'\excel.xlsx' Local $oWorkbook = _Excel_BookOpen($oExcel, $excelPath, True, False) sleep(2000) Local $aResult = _Excel_RangeRead($oWorkbook, Default, $oWorkbook.ActiveSheet.Usedrange.Columns("A:A")) sleep(2000) ;make storage location $newPath = $defaultLocal if(FileExists($newPath)) then DirCreate($newPath&"\Agreements\") DirCreate($newPath&"\Receipts\") DirCreate($newPath&"\ScreenShots\") endif ;create instance of IE and maximize window $IE = _IECreate("https://wnlisvc1.whynotleaseit.com/ccm/login.aspx") local $hWnd = winwaitactive("CRM Collection Portal Home Page - Internet Explorer","",2) winsetstate($hWnd, "", @SW_MAXIMIZE) ;Do login _IEFormElementSetValue(_IEGetObjByName($IE, "ctl00$ContentPlaceHolder1$txtUserName"), $username) _IEFormElementSetValue(_IEGetObjByName($IE, "ctl00$ContentPlaceHolder1$txtPassword"), $password) _IEaction(_IEGetObjByName($IE, "ctl00$ContentPlaceHolder1$btnLogIn"), "click") sleep(1000) ;do primary looping logic for $cell in $aResult doSearch($cell) _IEaction(_IEGetObjByName($IE, "ctl00$ContentPlaceHolder1$btnOK"), "click") _IEaction(_IEGetObjByName($IE, "ctl00$ContentPlaceHolder1$btnMultiple"), "click") _IEaction(_IEGetObjByName($IE, "ctl00$ContentPlaceHolder1$btnLeasedItems"), "click") sleep(500) $check = _IELinkClickByText($IE, "View Agreement") ;this is to prevent a crash that was occouring when a invalid ID was put in and the script had nothing to click. if(not $check <= 0)then winwaitactive("TEMPOE | Document Renderer - Internet Explorer","",2) doPDFPrint($newPath&"\Agreements\", $cell) send("^w") winwaitactive("CRM Collection Portal Home Page - Internet Explorer","",2) $validationString = $validationString&$cell&" success"&@lf Else ConsoleWrite("Click Failed") _ScreenCapture_Capture($newPath&"\Agreements\"&$cell&".jpg", (@DesktopWidth/2)-5, (@DesktopHeight/2)-5, (@DesktopWidth/2)+5, (@DesktopHeight/2)+5, False) $validationString = $validationString&$cell&" fail"&@lf endif $check = _IELinkClickByText($IE, "View Receipt") ;this is to prevent a crash that was occouring when a invalid ID was put in and the script had nothing to click. if(not $check <= 0)then winwaitactive("TEMPOE | Document Renderer - Internet Explorer","",2) doPDFPrint($newPath&"\Receipts\", $cell) send("^w") winwaitactive("CRM Collection Portal Home Page - Internet Explorer","",2) Else ConsoleWrite("Click Failed") _ScreenCapture_Capture($newPath&"\Receipts\"&$cell&".jpg", (@DesktopWidth/2)-5, (@DesktopHeight/2)-5, (@DesktopWidth/2)+5, (@DesktopHeight/2)+5, False) endif _ScreenCapture_Capture($newPath&"\ScreenShots\"&$cell&".jpg", (@DesktopWidth/2)-400, (@DesktopHeight/2)-200, (@DesktopWidth/2)+380, (@DesktopHeight/2)+200, False) ;_IEaction(_IEGetObjByName($IE, "ctl00$ContentPlaceHolder1$btnCancel13"), "click") _IEaction(_IEGetObjByName($IE, "ctl00$ContentPlaceHolder1$btnNewSearch"), "click") sleep(2000) next _IEQuit($IE) _Excel_Close($oExcel, false, true) Run("notepad") WinWaitActive("Untitled - Notepad") send($validationString) exit please send help! Link to comment Share on other sites More sharing options...
Developers Jos Posted March 23, 2017 Developers Share Posted March 23, 2017 37 minutes ago, Robobobatron said: please send help! Where should I fly to? Seriously: One difference could be the fact that the FileSelectFolder() function will also change the workdir to the selected path. Jos Xandy 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Robobobatron Posted March 23, 2017 Author Share Posted March 23, 2017 7 minutes ago, Jos said: FileSelectFolder() function will also change the workdir to the selected path. I am quite new to autoIt. what is it you are referring to when you say workdir? also, while that may be true, why would it get through get through several iterations and then fail if i was having some sort of mistargeted file reference? Link to comment Share on other sites More sharing options...
Developers Jos Posted March 23, 2017 Developers Share Posted March 23, 2017 2 minutes ago, Robobobatron said: I am quite new to autoIt. what is it you are referring to when you say workdir? Search on Working Directory ( the default directory for the running process) 2 minutes ago, Robobobatron said: also, while that may be true, why would it get through get through several iterations and then fail if i was having some sort of mistargeted file reference? That is as clear as mud Can you be more exact, but it could point to the difference I explained about the workdir. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Robobobatron Posted March 23, 2017 Author Share Posted March 23, 2017 i am certainly willing to try it. Link to comment Share on other sites More sharing options...
Robobobatron Posted March 23, 2017 Author Share Posted March 23, 2017 ok, i have tried changing the working directory to no avail. it still crashes after 5 iterations. to be more clear,if you look at the for-each loop, you will see i am executing code for every cell that was in the first row of my excel doc. it successfully get through the whole thing without issue in the one labeled successful. however, in......the other one.....it gets through 4 iterations completely, but then crashes on five after it does the final screen capture. Link to comment Share on other sites More sharing options...
Developers Jos Posted March 23, 2017 Developers Share Posted March 23, 2017 Ok . and what exactly do you mean by crash? It stops or gives any error? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Robobobatron Posted March 23, 2017 Author Share Posted March 23, 2017 1 minute ago, Jos said: Ok . and what exactly do you mean by crash? It stops or gives any error? Jos i am running this as an executable as the website is only accessible for a PC remote from where i am. its a hard stop complains of an error in the executable at an obscenely high line number(13833), outputs the name and location of the executable, and says "Error: The requested action with this object has failed." Link to comment Share on other sites More sharing options...
Developers Jos Posted March 23, 2017 Developers Share Posted March 23, 2017 3 minutes ago, Robobobatron said: obscenely high line number(13833) That is not really a correct statement as ypu have to imagine that AutoIt3 will merge all Include files at the place of the include statement, hence the high linenumber. Run your script through au3stripper with the /MO option to generate a single merged source file to find that linenumber and give you an idea what is happening. jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Robobobatron Posted March 23, 2017 Author Share Posted March 23, 2017 ok i used: #AutoIt3Wrapper_Run_Au3Stripper=y #Au3Stripper_Parameters=/MO at the top of my script, as this is how i understand how to use au3stripper. however, this still yielded the same line number. Link to comment Share on other sites More sharing options...
Developers Jos Posted March 23, 2017 Developers Share Posted March 23, 2017 Did au3stripper run and did you look at Scriptname_stripped.au3 generated by au3stripper? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Robobobatron Posted March 23, 2017 Author Share Posted March 23, 2017 no after attempting several permutations of the above code. it is not producing a "stripped" version of the script. at least not that i can find. so i must be calling the stripper wrong. how is it you are supposed to call it? it just call at the beginning of the script with the little preprocessing hash, right? Link to comment Share on other sites More sharing options...
Developers Jos Posted March 23, 2017 Developers Share Posted March 23, 2017 Show me the SciTE outputpane information that is created after a compile (F7) so I can see what is happening. You do have the separate SciTE4AutoIt3 installer also installed...right? JOs SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Robobobatron Posted March 23, 2017 Author Share Posted March 23, 2017 it sounds as though i am supposed to now something, and i dont, i am very dumb. my output looks the same as if you were to compile any script >"C:\Program Files (x86)\AutoIt3\SciTE\..\aut2exe\aut2exe.exe" /in "C:\Users\markf\Documents\SCS - WNL Media Auotmate.au3" >Exit code: 0 Time: 0.3594 >"C:\Program Files (x86)\AutoIt3\SciTE\..\aut2exe\aut2exe.exe" /in "C:\Users\markf\Documents\SCS - WNL Media Auotmate.au3" >Exit code: 0 Time: 0.3594 i have installed nothing extra, so it is unlikely i have installed what it is you are talking about. Link to comment Share on other sites More sharing options...
Developers Jos Posted March 23, 2017 Developers Share Posted March 23, 2017 (edited) 2 minutes ago, Robobobatron said: it sounds as though i am supposed to now something, and i dont, i am very dumb. No you are not. Your posted output tells me that you have not yet installed the separate SciTE4AutoIt3 installer so hence nothing happens. Just download and install it and you will see that AutoIt3Wrapper will be run which handles all these extra tools and #AutoIt3Wrapper_xxx directives. Jos Edited March 23, 2017 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Robobobatron Posted March 23, 2017 Author Share Posted March 23, 2017 HOOOOLLLY MOLY! its like whole new world of error flags and debugging! Link to comment Share on other sites More sharing options...
Developers Jos Posted March 23, 2017 Developers Share Posted March 23, 2017 That is the idea of this extra installer... make development more fun and better. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Robobobatron Posted March 23, 2017 Author Share Posted March 23, 2017 ok, after doing the changes the IDE suggested, i am still having the same problem here is my SciTE output: >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /NoStatus /prod /in "C:\Users\markf\Documents\SCS - WNL Media Auotmate2.au3" +>14:28:52 Starting AutoIt3Wrapper v.17.224.935.0 SciTE v.3.7.3.0 Keyboard:00000409 OS:WIN_10/ CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Users\markf\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\markf\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.14.2) from:C:\Program Files (x86)\AutoIt3 input:C:\Users\markf\Documents\SCS - WNL Media Auotmate2.au3 +>14:28:52 AU3Check ended.rc:0 >Running Au3Stripper (17.224.935.0) from:C:\Program Files (x86)\AutoIt3\SciTE\Au3Stripper cmdline: +> 0 Au3Stripper v17.224.935.0 finished merging 25299 lines of code, stripped 9753 comment lines and Merged 365 Continuation lines. +> Created:C:\Users\markf\Documents\SCS - WNL Media Auotmate2_stripped.au3 with 15181 lines. +>14:28:53 Au3Stripper ended.rc:0 >Running AU3Check (3.3.14.2) from:C:\Program Files (x86)\AutoIt3 input:C:\Users\markf\Documents\SCS - WNL Media Auotmate2_stripped.au3 +>14:28:53 AU3Check ended.rc:0 >Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\aut2exe\aut2exe.exe /in "C:\Users\markf\Documents\SCS - WNL Media Auotmate2_stripped.au3" /out "C:\Users\markf\AppData\Local\AutoIt v3\Aut2exe\~AU96B1.tmp.exe" /nopack /comp 2 +>14:28:54 Aut2exe.exe ended.C:\Users\markf\AppData\Local\AutoIt v3\Aut2exe\~AU96B1.tmp.exe. rc:0 +>14:28:54 Created program:C:\Users\markf\Documents\SCS - WNL Media Auotmate2.exe +>14:28:54 AutoIt3Wrapper Finished. >Exit code: 0 Time: 2.752 the error complains of a different but still very high number(13835) Link to comment Share on other sites More sharing options...
Developers Jos Posted March 23, 2017 Developers Share Posted March 23, 2017 (edited) 1 minute ago, Robobobatron said: Created:C:\Users\markf\Documents\SCS - WNL Media Auotmate2_stripped.au3 with 15181 lines. Looks to me that line does exists. Check this file as mentioned previously. Jos Edited March 23, 2017 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Robobobatron Posted March 23, 2017 Author Share Posted March 23, 2017 so here is the problem code in the stripped script: Func _IEGetObjByName(ByRef $oObject, $sName, $iIndex = 0) If Not IsObj($oObject) Then __IEConsoleWriteError("Error", "_IEGetObjByName", "$_IESTATUS_InvalidDataType") Return SetError($_IESTATUS_InvalidDataType, 1, 0) EndIf $iIndex = Number($iIndex) If $iIndex = -1 Then Return SetError($_IESTATUS_Success, $oObject.document.GetElementsByName($sName).length, $oObject.document.GetElementsByName($sName)) Else If IsObj($oObject.document.GetElementsByName($sName).item($iIndex)) Then Return SetError($_IESTATUS_Success, $oObject.document.GetElementsByName($sName).length, $oObject.document.GetElementsByName($sName).item($iIndex)) Else __IEConsoleWriteError("Warning", "_IEGetObjByName", "$_IESTATUS_NoMatch", "Name: " & $sName & ", Index: " & $iIndex) Return SetError($_IESTATUS_NoMatch, 0, 0) EndIf EndIf EndFunc and that would seem to make sense to a degree as the problem area in my code is: sleep(500) $work = _IEGetObjByName($IE, "ctl00$ContentPlaceHolder1$btnNewSearch") _IEaction($work, "click") however, it runs this code with out failure in the other script that does the same logic, just asks for user input. beyond that, it executes this code 4 times before failure, without issue. 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