Gianni Posted January 15, 2018 Posted January 15, 2018 An example on how to inject jQuery into a web page It can be useful to manage the page from AutoIt using jQuery. Idea from here: http://www.learningjquery.com/2009/04/better-stronger-safer-jquerify-bookmarklet Suggestions and improvements are welcome expandcollapse popup#include <ie.au3> Example() Func Example() Local $oIE = _IECreate("www.google.com") Local $jQuery = _jQuerify($oIE) MsgBox(0, "Version", "jQuery version: " & $jQuery.fn.jquery) MsgBox(0, "Example", "click ok to exit." & @CRLF & "Google logo will fade out by jQuery...") $jQuery('#hplogo').fadeOut(3000) ; jQuery will fade out the google logo EndFunc ;==>Example ; #FUNCTION# ==================================================================================================================== ; Name ..........: _jQuerify ; Description ...: ; Syntax ........: _jQuerify(Byref $oIE) ; Parameters ....: $oIE - Object variable of an InternetExplorer.Application. ; Return values .: an object variable pointing to the jQuery library ; Author ........: Chimp ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _jQuerify(ByRef $oIE) Local $jsEval, $jQuery, $otherlib = False ; create a reference to the javascript eval() function $oIE.document.parentWindow.setTimeout('document.head.eval = eval', 0) Do Sleep(250) $jsEval = Execute('$oIE.Document.head.eval') Until IsObj($jsEval) ; if jQuery is not already loaded then load it If $jsEval("typeof jQuery=='undefined'") Then ; check if the '$' (dollar) name is already in use by other library If $jsEval("typeof $=='function'") Then $otherlib = True Local $oScript = $oIE.document.createElement('script'); $oScript.type = 'text/javascript' ; If you want to load jQuery from a disk file use the following statement ; where i.e. jquery-1.9.1.js is the file containing the jQuery source ; (or also use a string variable containing the whole jQuery listing) ;~ $oScript.TextContent = FileRead(@ScriptDir & "\jquery-1.9.1.js") ; <--- from a file ; If you want to download jQuery from the web use this statement $oScript.src = 'https://code.jquery.com/jquery-latest.min.js' ; <--- from an url $oIE.document.getElementsByTagName('head').item(0).appendChild($oScript) Do Sleep(250) Until $jsEval("typeof jQuery == 'function'") EndIf Do Sleep(250) $jQuery = $jsEval("jQuery") Until IsObj($jQuery) If $otherlib Then $jsEval('jQuery.noConflict();') Return $jQuery EndFunc ;==>_jQuerify mLipok, Danp2, moimon and 1 other 4 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
argumentum Posted January 18, 2018 Posted January 18, 2018 I have IE8 in Win7 and the code did not do anything, no MsgBox, nothing. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Gianni Posted January 18, 2018 Author Posted January 18, 2018 Hi @argumentum, thanks for the feedback, I suppose you has trouble downloading the jQuer library from the link. try to see if you can download it manually (from the same link or find another one) and save it in the same directory of the script and then modify the AutoIt code by commenting out the line marked with "; <--- from an url" and use the line marked as "; <--- from a file" so to use a jQuery library loaded from the local file instead of from the url. (btw (I don't say for You, but I just say for the record) the file name in the "; <--- from a file" line has to be adjusted accordingly)." Please let us know what happens .... Thanks. Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
Gianni Posted January 21, 2018 Author Posted January 21, 2018 Hello, I've modified a bit the script to chek the IE version and use appropriate commands to get reference to the javascript eval() function. At the moment I've access only to an IE version 11 and I can not test if it works on IE < 11 Could someone please check if this script is working on IE versions lesser than 11. It should inject jquery (if not already present in the page), show the jquery version (injected or already present) and use jquery to make the google logo disappear from the page (just for a test). Thanks for the help expandcollapse popup#include <ie.au3> Example() Func Example() Local $oIE = _IECreate("www.google.com") Local $jQuery = _jQuerify($oIE) MsgBox(0, "Version", "jQuery version: " & $jQuery.fn.jquery) MsgBox(0, "Example", "click ok to exit." & @CRLF & "Google logo will fade out by jQuery...") $jQuery('#hplogo').fadeOut(3000) ; jQuery will fade out the google logo EndFunc ;==>Example ; #FUNCTION# ==================================================================================================================== ; Name ..........: _jQuerify ; Description ...: ; Syntax ........: _jQuerify(Byref $oIE) ; Parameters ....: $oIE - Object variable of an InternetExplorer.Application. ; Return values .: an object variable pointing to the jQuery library ; Author ........: Chimp ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _jQuerify(ByRef $oIE) Local $msie, $jsEval, $jQuery, $otherlib = False $msie = Execute('$oIE.document.documentMode') If ($msie = "") Or Number($msie) < 11 Then ; an IE version < 11 ; create a reference to the javascript eval() function $oIE.document.parentWindow.setTimeout('window.eval = eval', 0) Do Sleep(250) $jsEval = Execute('$oIE.Document.parentwindow.eval') Until IsObj($jsEval) Else ; IE version > = 11 ; create a reference to the javascript eval() function $oIE.document.parentWindow.setTimeout('document.head.eval = eval', 0) Do Sleep(250) $jsEval = Execute('$oIE.Document.head.eval') Until IsObj($jsEval) EndIf ; if jQuery is not already loaded then load it If $jsEval("typeof jQuery=='undefined'") Then ; check if the '$' (dollar) name is already in use by other library If $jsEval("typeof $=='function'") Then $otherlib = True Local $oScript = $oIE.document.createElement('script'); $oScript.type = 'text/javascript' ; If you want to load jQuery from a disk file use the following statement ; where i.e. jquery-1.9.1.js is the file containing the jQuery source ; (or also use a string variable containing the whole jQuery listing) ;~ $oScript.TextContent = FileRead(@ScriptDir & "\jquery-1.9.1.js") ; <--- from a file ; If you want to download jQuery from the web use this statement $oScript.src = 'https://code.jquery.com/jquery-latest.min.js' ; <--- from an url $oIE.document.getElementsByTagName('head').item(0).appendChild($oScript) Do Sleep(250) Until $jsEval("typeof jQuery == 'function'") EndIf Do Sleep(250) $jQuery = $jsEval("jQuery") Until IsObj($jQuery) If $otherlib Then $jsEval('jQuery.noConflict();') Return $jQuery EndFunc ;==>_jQuerify argumentum 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
tarretarretarre Posted February 15, 2018 Posted February 15, 2018 (edited) Good job! This will come in handy! EDIT @Chimp You can test all versions by using _IECreateEmbedded and setting FEATURE BROWSER EMULATION to emulate IE10 on Autoit.exe #RequireAdmin FEATURE_BROWSER_EMULATION("AutoIt3.exe", 10001) Func FEATURE_BROWSER_EMULATION($sExe, $iVer) Local $key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION" Local $key64 = "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION" ; If OS IS 64 bit If @OSArch === "X64" Then $key = $key64 RegWrite($key, $sExe, "REG_DWORD", $iVer) If @error Then Return SetError(@error) EndFunc Edited February 15, 2018 by tarretarretarre Socket-IO - An event-driven TCP UDF (Realtime chat example) AutoIt-API-WS - An expressive HTTP server you can use to build your own API with (Screenshots)
Burgs Posted April 7, 2018 Posted April 7, 2018 Greetings, I am attempting to use this code so as to be able to expose Jquery commands to AutoIT. It seems very promising however I keep getting this error: $oIE.document.parentWindow.setTimeout('document.head.eval = eval', 0) $oIE.document.parentWindow^ ERROR it happens in the part where the function checks if the IE version is "11" or better...can I get some idea what the problem is here? I'm using Windows 10. I thank you in advance if anybody can give an explanation...
Danp2 Posted April 7, 2018 Posted April 7, 2018 Suggest that you provide the following -- Exact version of Windows 10 Exact version of Internet Explorer Reproducer script Latest Webdriver UDF Release Webdriver Wiki FAQs
Burgs Posted April 8, 2018 Posted April 8, 2018 Thank you for the reply. As requested: Edition: Windows 10 Home Version: 1703 OS Build: 15063.909 System Type: 64-bit operating system, x64-based processor IE Info: (from 'Details' tab in 'Properties' of iexplore.exe in the "Internet Explorer" folder) File description: Internet Explorer Type: Application File Version: 11.0.15063.850 Product name: Internet Explorer Product Version: 11.00.15063.850 Date modified: 12/31/2017 6:17pm Original filename: IEXPLORE.EXE I actually seem to get the exact same error on 2 scripts I try to run...the first is the one from above, and the second is a script I believe that you ("Danp2") had provided on another post, if I am not mistaken. I simply copied/pasted and ran both scripts...I did not make any changes or adjustments.... expandcollapse popup#include <ie.au3> Example() Func Example() Local $oIE = _IECreate("www.google.com") Local $jQuery = _jQuerify($oIE) MsgBox(0, "Version", "jQuery version: " & $jQuery.fn.jquery) MsgBox(0, "Example", "click ok to exit." & @CRLF & "Google logo will fade out by jQuery...") $jQuery('#hplogo').fadeOut(3000) ; jQuery will fade out the google logo EndFunc ;==>Example ; #FUNCTION# ==================================================================================================================== ; Name ..........: _jQuerify ; Description ...: ; Syntax ........: _jQuerify(Byref $oIE) ; Parameters ....: $oIE - Object variable of an InternetExplorer.Application. ; Return values .: an object variable pointing to the jQuery library ; Author ........: Chimp ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _jQuerify(ByRef $oIE) Local $msie, $jsEval, $jQuery, $otherlib = False $msie = Execute('$oIE.document.documentMode') If ($msie = "") Or Number($msie) < 11 Then ; an IE version < 11 ; create a reference to the javascript eval() function $oIE.document.parentWindow.setTimeout('window.eval = eval', 0) Do Sleep(250) $jsEval = Execute('$oIE.Document.parentwindow.eval') Until IsObj($jsEval) Else ; IE version > = 11 ; create a reference to the javascript eval() function $oIE.document.parentWindow.setTimeout('document.head.eval = eval', 0) Do Sleep(250) $jsEval = Execute('$oIE.Document.head.eval') Until IsObj($jsEval) EndIf ; if jQuery is not already loaded then load it If $jsEval("typeof jQuery=='undefined'") Then ; check if the '$' (dollar) name is already in use by other library If $jsEval("typeof $=='function'") Then $otherlib = True Local $oScript = $oIE.document.createElement('script'); $oScript.type = 'text/javascript' ; If you want to load jQuery from a disk file use the following statement ; where i.e. jquery-1.9.1.js is the file containing the jQuery source ; (or also use a string variable containing the whole jQuery listing) ;~ $oScript.TextContent = FileRead(@ScriptDir & "\jquery-1.9.1.js") ; <--- from a file ; If you want to download jQuery from the web use this statement $oScript.src = 'https://code.jquery.com/jquery-latest.min.js' ; <--- from an url $oIE.document.getElementsByTagName('head').item(0).appendChild($oScript) Do Sleep(250) Until $jsEval("typeof jQuery == 'function'") EndIf Do Sleep(250) $jQuery = $jsEval("jQuery") Until IsObj($jQuery) If $otherlib Then $jsEval('jQuery.noConflict();') Return $jQuery EndFunc ;==>_jQuerify here is the second one (again same error on same line): expandcollapse popup#include <IE.au3> #include <MsgBoxConstants.au3> Local $strMainURL = "http://bidfta.bidqt.com/BidFTA/#/Main" Local $oIE = _IECreate($strMainURL) MsgBox(0,"pause","Press ok when page is ready") Local $oSelect = _IEGetObjByName($oIE, "LocationSelect") ;ControlSend("Main - Internet Explorer","","","e") _IEFormElementOptionSelect($oSelect,"Amelia, OH",1,"byText") Local $jQuery = _jQuerify($oIE) $jQuery("[name='LocationSelect']").trigger('change') MsgBox(0,"Done","Done") _IEQuit($oIE) ; #FUNCTION# ==================================================================================================================== ; Name ..........: _jQuerify ; Description ...: ; Syntax ........: _jQuerify(Byref $oIE) ; Parameters ....: $oIE - Object variable of an InternetExplorer.Application. ; Return values .: an object variable pointing to the jQuery library ; Author ........: Chimp ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _jQuerify(ByRef $oIE) Local $msie, $jsEval, $jQuery, $otherlib = False $msie = Execute('$oIE.document.documentMode') If ($msie = "") Or Number($msie) < 11 Then ; an IE version < 11 ; create a reference to the javascript eval() function $oIE.document.parentWindow.setTimeout('window.eval = eval', 0) Do Sleep(250) $jsEval = Execute('$oIE.Document.parentwindow.eval') Until IsObj($jsEval) Else ; IE version > = 11 ; create a reference to the javascript eval() function $oIE.document.parentWindow.setTimeout('document.head.eval = eval', 0) Do Sleep(250) $jsEval = Execute('$oIE.Document.head.eval') Until IsObj($jsEval) EndIf ; if jQuery is not already loaded then load it If $jsEval("typeof jQuery=='undefined'") Then ; check if the '$' (dollar) name is already in use by other library If $jsEval("typeof $=='function'") Then $otherlib = True Local $oScript = $oIE.document.createElement('script'); $oScript.type = 'text/javascript' ; If you want to load jQuery from a disk file use the following statement ; where i.e. jquery-1.9.1.js is the file containing the jQuery source ; (or also use a string variable containing the whole jQuery listing) ;~ $oScript.TextContent = FileRead(@ScriptDir & "\jquery-1.9.1.js") ; <--- from a file ; If you want to download jQuery from the web use this statement $oScript.src = 'https://code.jquery.com/jquery-latest.min.js' ; <--- from an url $oIE.document.getElementsByTagName('head').item(0).appendChild($oScript) Do Sleep(250) Until $jsEval("typeof jQuery == 'function'") EndIf Do Sleep(250) $jQuery = $jsEval("jQuery") Until IsObj($jQuery) If $otherlib Then $jsEval('jQuery.noConflict();') Return $jQuery EndFunc ;==>_jQuerify Any help is seriously appreciated...I really need to be able to use actual Jquery commands within AutoIT for a task I need to automate asap...
Danp2 Posted April 8, 2018 Posted April 8, 2018 First thing I would check is that your Windows installation is fully patched with the latest updates from MS. Besides the edition (Home vs Pro), I see that we are on different releases of Windows 10. You could try updating to the later Fall Creators Update to see if the issue is resolved. Latest Webdriver UDF Release Webdriver Wiki FAQs
Burgs Posted April 9, 2018 Posted April 9, 2018 Howdy, Thanks for the response. I have updated my Windows 10. The update took a while but seemed to go fine without any problems. I now seem to be up to date and no additional updates are available at this time. I still have exactly the same problem with this script. Any work-arounds...? Plan B...? Thanks in advance.
Danp2 Posted April 9, 2018 Posted April 9, 2018 What happens if you do the following -- Open the IE Developer Tools by hitting F12 Switch to the console tab Enter the string "document.parentWindow" (without the quotes) Press Enter Latest Webdriver UDF Release Webdriver Wiki FAQs
Danp2 Posted April 9, 2018 Posted April 9, 2018 You could also try adding a COM error handler (see ObjEvent in the help file) to see if that yields any additional details on why the command is failing. Latest Webdriver UDF Release Webdriver Wiki FAQs
Burgs Posted April 10, 2018 Posted April 10, 2018 Hi again, I used the 'Developer Tools/Console' as suggested...using the browser window that opened up "Google" by running that first 'Jquerify' script. I got a lot of "undefined" in [Object Window]...which I assume is not good...and likely the reason I cannot run these scripts...? Now the obvious question is what is causing this? My OS is up to date with the latest updates, IE should be as well since Windows 10 keeps it so...'Active Scripting' is also 'enabled' within IE...what am I missing here? thanks again for your help.
Danp2 Posted April 10, 2018 Posted April 10, 2018 Can't tell from your reply if you tried the suggestions from my last two posts. Please advise. Latest Webdriver UDF Release Webdriver Wiki FAQs
Burgs Posted April 10, 2018 Posted April 10, 2018 Hi, Have not tried to implement a COM error handler yet...however from your first suggestion: " Open the IE Developer Tools by hitting F12 Switch to the console tab Enter the string "document.parentWindow" (without the quotes) Press Enter " It reported a huge long list of items, however it begins with " [Object Window] " and then soon after lists 4 or 5 "undefined"... Am I correct in assuming there should be no "undefined" response from the "document.parentWindow" entry...? If that is the case then that might give a reason why I cannot execute the script(s)...however I do not know what is necessary to correct this issue nor the cause of it.
Danp2 Posted April 10, 2018 Posted April 10, 2018 3 minutes ago, Burgs said: It reported a huge long list of items, however it begins with " [Object Window] " and then soon after lists 4 or 5 "undefined"... No, that's actually what I would expect to see. So this simple test proves that the document.parentWindow object exists and is accessible from the developer tools. Now need to figure out why the command is failing from within the Autoit code. Please report back once you've tested with a COM error handler in place. Latest Webdriver UDF Release Webdriver Wiki FAQs
Burgs Posted April 10, 2018 Posted April 10, 2018 (edited) Hello again, I copied the COM ObjEvent script from the documentation...simply removing the 'intentional' error, as such: expandcollapse popup#include <MsgBoxConstants.au3> Example() Func Example() ; Error monitoring. This will trap all COM errors while alive. ; This particular object is declared as local, meaning after the function returns it will not exist. Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") ; Create Internet Explorer object Local $oIE = ObjCreate("InternetExplorer.Application") ; Check for errors If @error Then Return $oIE.Visible = True ; set visibility ; Custom sink object Local $oIEEvents = ObjEvent($oIE, "_IEEvent_", "DWebBrowserEvents2") ; Navigate somewhere $oIE.navigate("http://www.google.com/") ; Check for errors while loading If @error Then $oIE.Quit() Return EndIf ; Wait for page to load While 1 If $oIE.readyState = "complete" Or $oIE.readyState = 4 Then ExitLoop Sleep(10) WEnd ;; Deliberately cause error by calling non-existing method ;$oIE.PlayMeARockAndRollSong() ; Check for errors If @error Then MsgBox($MB_SYSTEMMODAL, "COM Error", "@error is set to COM error number." & @CRLF & "@error = 0x" & Hex(@error)) ; Wait few seconds to see if more events will be fired Sleep(3000) ; Nothing more to do. Close IE and return from the function $oIE.Quit() #forceref $oErrorHandler, $oIEEvents EndFunc ;==>Example ; BeforeNavigate2 method definition Func _IEEvent_BeforeNavigate2($oIEpDisp, $sIEURL, $iIEFlags, $sIETargetFrameName, $sIEPostData, $iIEHeaders, $bIECancel) ConsoleWrite("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!--BeforeNavigate2 fired--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! " & @CRLF & _ "$oIEpDisp = " & $oIEpDisp() & " - " & ObjName($oIEpDisp) & @CRLF & _ ; e.g. default property and name for the object "$sIEURL = " & $sIEURL & @CRLF & _ "$iIEFlags = " & $iIEFlags & @CRLF & _ "$sIETargetFrameName = " & $sIETargetFrameName & @CRLF & _ "$sIEPostData = " & $sIEPostData & @CRLF & _ "$iIEHeaders = " & $iIEHeaders & @CRLF & _ "$bIECancel = " & $bIECancel & @CRLF & _ "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! " & @CRLF & @CRLF) EndFunc ;==>_IEEvent_BeforeNavigate2 ; User's COM error function. Will be called if COM error occurs Func _ErrFunc($oError) ; Do anything here. ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _ @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _ @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _ @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _ @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF) EndFunc ;==>_ErrFunc When I run this it does report the following problem in the debug console: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ObjEvent_Test.au3 (51) : ==> COM Error intercepted ! err.number is: 0x80070005 err.windescription: Access is denied. err.description is: err.source is: err.helpfile is: err.helpcontext is: err.lastdllerror is: 0 err.scriptline is: 51 err.retcode is: 0x00000000 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Is that information useful...? Forgive my ignorance I'm not familiar with usage of COM objects. Thank you again for your help. Edited April 10, 2018 by Burgs
Danp2 Posted April 10, 2018 Posted April 10, 2018 Do the results vary if you make the following changes? Manually load Google.com in IE Use _IEAttach instead of _IECreate to get a reference to the IE object Latest Webdriver UDF Release Webdriver Wiki FAQs
Burgs Posted April 10, 2018 Posted April 10, 2018 Hi, Not sure if I did this properly, but here is my code now (note: I believe you intended to write 'ObjCreate' instead of 'IECreate')...so I commented out that line and inserted the '_IEAttach' line. expandcollapse popup#include <IE.au3> #include <MsgBoxConstants.au3> Example() Func Example() ; Error monitoring. This will trap all COM errors while alive. ; This particular object is declared as local, meaning after the function returns it will not exist. Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") ; Create Internet Explorer object ;Local $oIE = ObjCreate("InternetExplorer.Application") Local $oIE = _IEAttach("Google") MsgBox($MB_SYSTEMMODAL, "The URL", _IEPropertyGet($oIE, "locationurl")) ; Check for errors If @error Then Return $oIE.Visible = True ; set visibility ; Custom sink object Local $oIEEvents = ObjEvent($oIE, "_IEEvent_", "DWebBrowserEvents2") ;; Navigate somewhere ;$oIE.navigate("http://www.google.com/") ;; Check for errors while loading ;If @error Then ; $oIE.Quit() ; Return ;EndIf ; Wait for page to load While 1 If $oIE.readyState = "complete" Or $oIE.readyState = 4 Then ExitLoop Sleep(10) WEnd ;; Deliberately cause error by calling non-existing method ;$oIE.PlayMeARockAndRollSong() ; Check for errors If @error Then MsgBox($MB_SYSTEMMODAL, "COM Error", "@error is set to COM error number." & @CRLF & "@error = 0x" & Hex(@error)) ; Wait few seconds to see if more events will be fired Sleep(3000) ; Nothing more to do. Close IE and return from the function $oIE.Quit() #forceref $oErrorHandler, $oIEEvents EndFunc ;==>Example ; BeforeNavigate2 method definition Func _IEEvent_BeforeNavigate2($oIEpDisp, $sIEURL, $iIEFlags, $sIETargetFrameName, $sIEPostData, $iIEHeaders, $bIECancel) ConsoleWrite("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!--BeforeNavigate2 fired--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! " & @CRLF & _ "$oIEpDisp = " & $oIEpDisp() & " - " & ObjName($oIEpDisp) & @CRLF & _ ; e.g. default property and name for the object "$sIEURL = " & $sIEURL & @CRLF & _ "$iIEFlags = " & $iIEFlags & @CRLF & _ "$sIETargetFrameName = " & $sIETargetFrameName & @CRLF & _ "$sIEPostData = " & $sIEPostData & @CRLF & _ "$iIEHeaders = " & $iIEHeaders & @CRLF & _ "$bIECancel = " & $bIECancel & @CRLF & _ "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! " & @CRLF & @CRLF) EndFunc ;==>_IEEvent_BeforeNavigate2 ; User's COM error function. Will be called if COM error occurs Func _ErrFunc($oError) ; Do anything here. ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _ @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _ @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _ @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _ @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF) EndFunc ;==>_ErrFunc I manually opened up an IE browser and typed in 'www.google.com' into the search bar. When the page was loaded I ran this script above. Here are the complete debug console notifications: >"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\Stephen\Desktop\ObjEvent_Test.au3" --> IE.au3 T3.0-2 Warning from function _IEAttach, Cannot register internal error handler, cannot trap COM errors (Use _IEErrorHandlerRegister() to register a user error handler) ObjEvent_Test.au3 (350) : ==> COM Error intercepted ! err.number is: 0x80020009 err.windescription: Exception occurred. err.description is: err.source is: err.helpfile is: err.helpcontext is: 0 err.lastdllerror is: 0 err.scriptline is: 350 err.retcode is: 0x80004002 --> IE.au3 T3.0-2 Warning from function _IEAttach, Cannot register internal error handler, cannot trap COM errors (Use _IEErrorHandlerRegister() to register a user error handler) --> IE.au3 T3.0-2 Warning from function _IEAttach, Cannot register internal error handler, cannot trap COM errors (Use _IEErrorHandlerRegister() to register a user error handler) --> IE.au3 T3.0-2 Warning from function internal function __IEIsObjType, Cannot register internal error handler, cannot trap COM errors (Use _IEErrorHandlerRegister() to register a user error handler) --> IE.au3 T3.0-2 Warning from function internal function __IEIsObjType, Cannot register internal error handler, cannot trap COM errors (Use _IEErrorHandlerRegister() to register a user error handler) >Exit code: 0 Time: 6.325 I hope that is along the lines of what you were instructing me to do...and if so then I hope it is helpful information. Thanks again.
Danp2 Posted April 10, 2018 Posted April 10, 2018 No. I meant to modify the original script to use _ieattach instead of _iecreate. Trying to see if maybe the issue is related to page not being fully loaded. Latest Webdriver UDF Release Webdriver Wiki FAQs
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