plastix Posted March 25, 2006 Posted March 25, 2006 Hi all. During a loop that monitors a IE browser window (title "webmail") the script waits for a given page to load by checking page content. If the browser is closed during this loop, then the following functions (and possibly others) will fail as the IE object is no longer present: _IEAttach _IELoadWait This results in the script failing / terminating the application & breaking out of the loop etc. Is there any way to avoid this "break" so that it continues within the loop (when another browser session is started, it will detect it etc) - I should say that this occurs running the script beta in SciTe - but i would imagine the same would happen if it were compiled etc. I noticed a similar thread highlighting object pointer errors in the same functions due to page redirects / slow loading etc etc - but this won't be helped by those mods. TIA
DaleHohm Posted March 25, 2006 Posted March 25, 2006 (edited) Hi all. During a loop that monitors a IE browser window (title "webmail") the script waits for a given page to load by checking page content. If the browser is closed during this loop, then the following functions (and possibly others) will fail as the IE object is no longer present: _IEAttach _IELoadWait This results in the script failing / terminating the application & breaking out of the loop etc. Is there any way to avoid this "break" so that it continues within the loop (when another browser session is started, it will detect it etc) - I should say that this occurs running the script beta in SciTe - but i would imagine the same would happen if it were compiled etc. I noticed a similar thread highlighting object pointer errors in the same functions due to page redirects / slow loading etc etc - but this won't be helped by those mods. TIA I would not expect _IEAttach to create an error, only to return 0. There are several approaches to checking whether the browser still exists... One simple one would be _IEGetProperty($oIE,"readystate") -- this will return 0 of the browser has been destroyed, so you could do something like: If _IEGetProperty($oIE,"readystate") Then ;;; do something EndIf You can also set up an OnQuit event handler using ObjEvent that could take other action for you... This would prevent the need to check status of the browser before every operation: $oSink = ObjEvent($oIE, "IEEvent_") Func IEEvent_OnQuit() ;;; do something EndFunc Dale Edit: typo Edited March 25, 2006 by DaleHohm Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble
plastix Posted March 26, 2006 Author Posted March 26, 2006 thanks once again DaleHolm. The _IEEvent method didn't seem to trap anything / fire... Looking at the syntax in the help file i wonder whether i should supply an interface argument aswell... Trapping Auto-it errors stops the script ending most of the time... but one error that gets through is the highlighted line of the IE.au3 (both in _IEFormElementGetObjByName & _IEFormGetObjByName) if the browser gets closed. Func _IEFormElementGetObjByName($o_object, $s_name, $i_index = 0) ; $o_object - form object ; return object reference to specific form element If IsObj($o_object.elements.item ($s_name, $i_index)) Then SetError(0) Return $o_object.elements.item ($s_name, $i_index) Else SetError(1) Return 0 EndIf EndFunc ;==>_IEFormElementGetObjByName I get aC:\Program Files\AutoIt3\beta\webmail.au3 (856) : ==> Missing right bracket ')' in expression.: If IsObj($o_object.document.forms.item ($s_name, $i_index)) Then If IsObj(^ ERROR[i should point out that i pasted the whole IE.au3 into the script - but get the same as an include etc] Weird... again, it is when the browser is closed. I'll post my code in a sec...
plastix Posted March 26, 2006 Author Posted March 26, 2006 (edited) expandcollapse popup#include <array.au3> #include <Constants.au3> #include <IE.au3> While 1 WinWaitActive("Webmail") $oIE = _IEAttach("Webmail","Title") $oSink = ObjEvent("AutoIt.Error","MyErrFunc") If Not isObj($oIE) Then msgbox(0,"Oops","didn't attach to IE") While 1 Do _IELoadWait($oIE) $body = _IEBodyReadHTML($oIE) Sleep(500) Until StringInStr($body, "<B>COMPOSE MESSAGE</B>") If Not StringInStr($body,"<B>COMPOSE MESSAGE</B> (") Then $newbody = StringReplace($body, "<B>COMPOSE MESSAGE</B>", "<B>COMPOSE MESSAGE</B> (Monitored)") _IEBodyWriteHTML($oIE, $newbody) EndIf While isObj(_IEFormGetObjByName($oIE, "composeform")) $o_Form = _IEFormGetObjByName($oIE, "composeform") If _IEGetProperty($oIE,"readystate") Then $o_attach = _IEFormElementGetObjByName($o_Form, "attachment") $attachfile = _IEFormElementGetValue($o_attach) $file_ext = StringSplit($attachfile,".") If $file_ext[0] = 1 And Not $file_ext = "" Then msgbox(0,"Oops","Selected file doesn't seem to have an extension at all...") If $file_ext[0] > 1 And NOT ($file_ext[$file_ext[0]] = "safe") Then _GrumbleAboutIt() sleep(200) WEnd WEnd WEndTo help, i have made a simplified version of the webmail system (ie including relevant image buttons / labels etc etc) HERE. Ultimately, the script should detect that it is on the first page and click the image with the Alt="Compose new message", then monitor the compose page.I couldn't get the system to read the text in the main browser window, so i used IEBodyReadHTML() to get code and search for relevant strings...The system should run continuously - with an outer loop looking to attach to IE session on the Webmail site.It will, ultimately, "see" the compose image button via its 'Alt' and click to take to compose page.It should detect the compose page from the "COMPOSE MESSAGE" textMonitor the file field - if it isn't empty, check the extension and "grumble" if it isn't correct / clear the field [this bit is working nicely]Browsing away / closing browser shouldn't crash scriptThe main problem, I'm sure, is my methods for monitoring the pages - resulting in objects that vanish when move away etc etc.Any 'pointers' always greatly appreciated EDIT: Figured out another part of the problem - the system never breaks out of the internal loops once it attached to an IE process... moving the WinWaitActive / _IEAttach to the 'middle' loop (ie getting rid of the 'outer/parent' loop) keeps it running when browser closed etc... so really only the trapping of IE closing during page analysis | ensuring page present should make it stable. Edited March 26, 2006 by plastix
DaleHohm Posted March 26, 2006 Posted March 26, 2006 thanks once again DaleHolm. The _IEEvent method didn't seem to trap anything / fire... Looking at the syntax in the help file i wonder whether i should supply an interface argument aswell... Trapping Auto-it errors stops the script ending most of the time... but one error that gets through is the highlighted line of the IE.au3 (both in _IEFormElementGetObjByName & _IEFormGetObjByName) if the browser gets closed. I get a[i should point out that i pasted the whole IE.au3 into the script - but get the same as an include etc] Weird... again, it is when the browser is closed. I'll post my code in a sec...OK, I have time for a little more thoughtful reply. Sorry, the event name for Quit is Quit rather than OnQuit. I've tested and this works:$oSink = ObjEvent($oIE, "IEEvent_") Func IEEvent_Quit() ConsoleWrite("We're in the Quit Event" & @CR) EndFunc You can also trap all COM errors with a special case of the ObjEvent function... this is documented in the helpfile:$oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler ; This is my custom error handler Func MyErrFunc() $HexNumber=hex($oMyError.number,8) Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _ "Number is: " & $HexNumber & @CRLF & _ "Windescription is: " & $oMyError.windescription ) SetError(1); something to check for when this function returns Endfunc This will prevcent your script from bailing out and it is up to you to trap and handle any errors. Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble
plastix Posted March 26, 2006 Author Posted March 26, 2006 hi DaleHolm. Yep - i looked up the IEEvents on MSDN and found that was Quit - which traps the IEQuit nicely now. I think i still get the odd random "missing right bracket" if i navigate around the pages quickly - but i'll test more with the custom COM error trapping and see if it is still a problem. Thanks +++. Really learning here. Thanks for your time.
plastix Posted April 6, 2006 Author Posted April 6, 2006 OK.Despite all efforts, script is still failing with a "missing right ')' bracket" on this line of _IEFormGetObjByName() if the browser is closed down (this is not all the time - just when you catch it checking form elements periodically):If IsObj($o_object.document.forms.item($s_name, $i_index)) Then If IsObj(^ ERROREven when i check that the object exists prior to calling function, and with COM error handling enabled to trap autoit errors, and IEEvents to catch IE closing, some still get through and causing script to close.Any additional thoughts greatly appreciated
DaleHohm Posted April 6, 2006 Posted April 6, 2006 OK. Despite all efforts, script is still failing with a "missing right ')' bracket" on this line of _IEFormGetObjByName() if the browser is closed down (this is not all the time - just when you catch it checking form elements periodically):If IsObj($o_object.document.forms.item($s_name, $i_index)) Then If IsObj(^ ERROREven when i check that the object exists prior to calling function, and with COM error handling enabled to trap autoit errors, and IEEvents to catch IE closing, some still get through and causing script to close. Any additional thoughts greatly appreciated It is possible that you are experiencing a timing issue that I believe I finally understand having to do with the IE object not being ready before checking document properties. You may want to try this replacement code that is the basis for the function that is in the next, as yet, unreleased version: Func _IELoadWait($o_object, $i_delay = 0) ; test version -- get rid of object timing error? If IsObj($o_object) Then Sleep($i_delay) If ObjName($o_object) = "IWebBrowser2" Then While (_IEGetProperty($o_object, "readyState") <> "complete") and _ (_IEGetProperty($o_object, "readyState") <> 4) Sleep(100) WEnd EndIf While ($o_object.document.readyState <> "complete") and _ ($o_object.document.readyState <> 4) Sleep(100) WEnd SetError(0) Return 1 Else SetError(1) Return 0 EndIf EndFunc;==>_IELoadWait Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble
plastix Posted April 6, 2006 Author Posted April 6, 2006 hi DaleHohmI have substituted the new code, but it hasn't helped the problem.The problem occurs due to the script confirming IE is open and on the selected email form (as mentioned above) - it then enters a loop checking the contents of the form using the _IEFormGetObjByName() and _IEFormElementGetObjByName() functions - should someone browse away, the "ieready" etc checks trap that etc... but if the browser is closed just after the script has "confirmed" IE is open & on relevant page, then these objects no longer exist, and throws an error in the relevant function.What is odd is that the function generates a "missing bracket" syntax error. If it generated any other error, i suspect that the COM trapping would work etc - because of this "syntax" error, the script fails inc. error trapping.If i come up with a workaround, i'll let you all know
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