SchneiMi Posted January 11, 2018 Posted January 11, 2018 (edited) Hello, it is difficult to explain. I have a script that works most of the time. But when I continue to call f.i. Action "search reference", I get Trouble - depending on the error handling Framework. Background: I have created a gui with several Buttons to call individual Actions. "open file", "search reference", "start Transfer" ... When I click "search reference", the function searchReference is called. The function attaches to or creates a new IE browser object, opens a search form, enters some query data and clicks the search button. Here's the beginning of the func Code: Quote Func searchReference() $oIE = getLoadedSearchForm() If not IsObj($oIE) Then msgbox(0, "Error", "Page could not be loaded, please try again later") Return False EndIf print("object: " & objName($oIE)) $oIE.document.getElementsByName("prop_typestring_36_editable_document_like")(0).value = $sReference $oIE.document.getElementsByName("prop_typestring_38_editable_document_eq")(0).value = "" $oIE.document.getElementsByName("prop_typestring_38_editable_document_eq")(0).fireEvent("onChange") Without ObjEvent handler, it either runs through, or after some times a window Pops up "AutoIt v3 Script doesn't work anymore" (translated) => Button "Close program". Exit Code: 3221225477. Or I get an error: Quote "C:\start.au3" (185) : ==> The requested action with this object has failed.: $oIE.document.getElementsByName("prop_typestring_38_editable_document_eq")(0).fireEvent("onChange") $oIE.document^ ERROR" Or another time this one: Quote "C:\start.au3" (201) : ==> The requested action with this object has failed.: local $oRows = $oIE.document.querySelectorAll("table tr.wcmListViewRowOdd[actionskey], table tr.wcmListViewRowEven[actionskey]") local $oRows = $oIE.document^ ERROR" Later I Extended it by lines to check for com Errors and savely return with False: Quote Func searchReference() $oIE = getLoadedSearchForm() If not IsObj($oIE) Then msgbox(0, "Error", "Page could not be loaded, please try again later") Return False EndIf print("object: " & objName($oIE)) $oIE.document.getElementsByName("prop_typestring_36_editable_document_like") If checkError(@error, "could not find reference field") Then Return False $oIE.document.getElementsByName("prop_typestring_36_editable_document_like")(0).value = $sReference $oIE.document.getElementsByName("prop_typestring_38_editable_document_eq")(0) If checkError(@error, "could not find document status field") Then Return False $oIE.document.getElementsByName("prop_typestring_38_editable_document_eq")(0).value = "" $oIE.document.getElementsByName("prop_typestring_38_editable_document_eq")(0).fireEvent("onChange") With the Default _IE error handler I get SciTE output: Quote object: IWebBrowser2 --> COM Error encountered in start.au3 (200) : ----> $IEComErrorNumber = 0x80020008 (-2147352568) ----> $IEComErrorWinDescription = Falscher Variablentyp. ----> $IEComErrorDescription = ----> $IEComErrorSource = ----> $IEComErrorHelpFile = ----> $IEComErrorHelpContext = ----> $IEComErrorLastDllError = 0 ----> $IEComErrorRetcode = 0x00000000 !(-2147352568) Custom message for autoit error position: could not find reference field Last line gives the hint where it happened in the Code. It is generated by the checkError-function. Why does it work most of the time, and sometimes Reports one or another or a third different error, although the site is visible and complete in the Background, all the time. The fields are definitely all there and when I enter the Code to Access the dom objects in the IE console, they are always found. :-( BR Michael Edited January 11, 2018 by SchneiMi Refers only to the crash and different error messages when run multiple times.
mLipok Posted January 11, 2018 Posted January 11, 2018 first get Local $oIEDoc = $oIE.document check errors and if no @errors occurs then you can use $oIEDoc.getElementsByName Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24
SchneiMi Posted January 12, 2018 Author Posted January 12, 2018 18 hours ago, mLipok said: first get Local $oIEDoc = $oIE.document check errors and if no @errors occurs then you can use $oIEDoc.getElementsByName What is the Intention behind this Approach, how would it avoid the Problem? The script runs smoothly for an arbitrary amount of time, when suddenly I cannot Access an object that I could Access just before? In one function call I get the error on getElementsByName of the fireEvent line, another time .value = $sReference line. Does AutoIt choke on calling com objects in a path, like $oIE.document.url...? Water mentioned in a parallel thread that there have been Problems in older versions of AutoIt when accessing com object paths. Last but not least, it would be difficult to implement this Workaround/way in my script for the full path of 100-200 com object calls. And the occurrance of Errors is also not reliable. This morning I've got an error after about 5 tries, now I don't get an error in 50 tries. :-(
SchneiMi Posted January 12, 2018 Author Posted January 12, 2018 19 hours ago, mLipok said: first get Local $oIEDoc = $oIE.document check errors and if no @errors occurs then you can use $oIEDoc.getElementsByName Maybe this helps, it's another example from the same script, here from a function that builds up a Connection to MS Excel and saving some references in AutoIt variables. Quote print("workbook: " & ObjName($oWorkbook) & " - " & $oWorkbook.Name) print("sheetcount: " & $oWorkbook.Sheets.Count) $oSheet = $oWorkbook.Sheets("Mapped") $oStatusSheet = $oWorkbook.Sheets("Status") $sReference = $oSheet.Range("Reference").value SciTE Output: Quote workbook: _Workbook - eingabe.xlsm sheetcount: 20 =====> COM Fehler: -2147352568 - Falscher Variablentyp. (line: 1925) =====> COM Fehler: -2147352568 - Falscher Variablentyp. (line: 1926) =====> COM Fehler: 169 - Variable must be of type 'Object'. (line: 1927) I think this is Close to what you asked for, assigning the Sheet object "Mapped" from the Collection to $oSheet. Ok, the next step would have been to save a collection's reference in an extra variable, but it is clear that the Collection object is accessible, returning the correct number of contained Sheets.
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