NRK Posted April 26, 2018 Share Posted April 26, 2018 (edited) Hi All, The below mentioned code to highlight HTML element under mouse pointer works fine. But it fails intermittently in the $oDoc.elementFromPoint call and exits the script. The error number is "0x80020008" and the error description is "Bad variable type". I am using 64 bit windows 7 Enterprise edition Service pack1 with IE 11. Please help me in solving this issue. I tried all possible combinations to make it work consistently, but still it fails. If it is a known open issue, please let me know any alternate approach without using elementFromPoint call. Thanks for your support. expandcollapse popup#include <IE.au3> #include <WinAPI.au3> #include <GUIConstantsEx.au3> ; #include <WinAPIEx.au3> #include <WindowsConstants.au3> Local $oIE = _IECreate("https://www.autoitscript.com/forum/") Local $oDoc = _IEDocGetObj($oIE) Local $oIE_hwnd = _IEPropertyGet($oIE, "hwnd") Local $oElement, $oElement_save, $aMousePos Local $aBrowserPos[6] ; x , y , width , height , x right , y bottom Local $aOverlayPos[4] ; coordinates of the overlay frame ; Create a Phantom window with a visible frame Local $aParentPos, $AlphaKey = 0xABABAB Local $iBorderColor = 0x00FF00, $iBorderThickness = 5 $hOverlay = GUICreate("", -50, -50, 10, 10, $WS_POPUPWINDOW, $WS_EX_LAYERED + $WS_EX_TOPMOST) ; transparent $Panel = GUICreate("", 48, 48, 10, 10, $WS_CHILD + $WS_VISIBLE, -1, $hOverlay) ; this new window becomes a child of $hOverlay window GUISetBkColor($iBorderColor, $hOverlay) GUISetBkColor($AlphaKey, $Panel) _WinAPI_SetLayeredWindowAttributes($hOverlay, $AlphaKey, 0, $LWA_COLORKEY) GUISetState(@SW_SHOW, $hOverlay) While WinExists($oIE_hwnd) $aMousePos = MouseGetPos() ; Now we get reference to the DOM object behind the mouse pointer $oElement = $oDoc.elementFromPoint($aMousePos[0] - $oIE.document.parentwindow.screenLeft, $aMousePos[1] - $oIE.document.parentwindow.screenTop) If IsObj($oElement) And $oElement <> $oElement_save Then $oElement_save = $oElement $aBrowserPos[0] = Int($oIE.document.parentwindow.screenLeft) ; X position on the desktop of the left edge of the browser $aBrowserPos[1] = Int($oIE.document.parentwindow.screenTop) ; Y position on the desktop of the top border of the browser $aBrowserPos[2] = Int($oIE.document.documentElement.clientWidth) ; Width of browser's client area $aBrowserPos[3] = Int($oIE.document.documentElement.clientHeight) ; Height of browser's client area $aBrowserPos[4] = $aBrowserPos[0] + $aBrowserPos[2] ; X position on the desktop of the right border of the browser $aBrowserPos[5] = $aBrowserPos[1] + $aBrowserPos[3] ; Y position on the desktop of the bottom border of the browser ; $oRect = $oElement.getBoundingClientRect() ; coordinates of the DOM object within the client area of the browser ; $aOverlayPos[0] = Int($oRect.left) + $aBrowserPos[0] ; X position of the left overlay border (absolute desktop coordinates) If $aOverlayPos[0] < $aBrowserPos[0] Then $aOverlayPos[0] = $aBrowserPos[0] ; if left border of the DOM obj is out of browser, overlay border stays anyway within the screen $aOverlayPos[1] = Int($oRect.Top) + $aBrowserPos[1] ; Y position of the top overlay border If $aOverlayPos[1] < $aBrowserPos[1] Then $aOverlayPos[1] = $aBrowserPos[1] ; if top border of obj is out of browser, overlay border stays anyway within the screen $aOverlayPos[2] = Int($oRect.right - $oRect.left) ; width of the obj If $aOverlayPos[0] + $aOverlayPos[2] > $aBrowserPos[4] Then $aOverlayPos[2] = $aBrowserPos[4] - $aOverlayPos[0] ; if obj's width is out of bounds, force the edge within the browser $aOverlayPos[3] = Int($oRect.bottom - $oRect.top) ; Height of the obj If $aOverlayPos[1] + $aOverlayPos[3] > $aBrowserPos[5] Then $aOverlayPos[3] = $aBrowserPos[5] - $aOverlayPos[1] ; stay within browser's bounds ; WinMove($hOverlay, "", $aOverlayPos[0], $aOverlayPos[1], $aOverlayPos[2], $aOverlayPos[3]) $aParentPos = WinGetPos($hOverlay) ; x, y, width, height WinMove($Panel, "", $iBorderThickness - 1, $iBorderThickness - 1, Int($aParentPos[2] - $iBorderThickness * 2), Int($aParentPos[3] - $iBorderThickness * 2)) EndIf WEnd Edited April 26, 2018 by Melba23 Added code tags Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 26, 2018 Moderators Share Posted April 26, 2018 NRK, Welcome to the AutoIt forums. But please stick to just the one thread in future - I have deleted the other one. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
NRK Posted April 26, 2018 Author Share Posted April 26, 2018 Sure, Posted in the wrong place, hence posted it here again. Link to comment Share on other sites More sharing options...
Danp2 Posted April 26, 2018 Share Posted April 26, 2018 Adding a COM error handler will solve this issue. One way to accomplish this would be to call _IEErrorHandlerRegister() at the beginning of your script. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
NRK Posted April 26, 2018 Author Share Posted April 26, 2018 Danp2, Thanks for the response. I will test this and confirm. Link to comment Share on other sites More sharing options...
mLipok Posted April 26, 2018 Share Posted April 26, 2018 Could you also say something about AutoIt and InternetExplorer version which you use ? 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 Link to comment Share on other sites More sharing options...
NRK Posted April 26, 2018 Author Share Posted April 26, 2018 By adding _IEErrorHandlerRegister(), it intercepts the COM error and continues the loop, however after handling the error for around 30 times, it comes out the program with exit code 255. Here is the updated code which I used to test it with _IEErrorHandlerRegister() added. I guess it comes out of the script because of the way in which it is coded inside elementFromPoint. Please share your thoughts and possible solutions. expandcollapse popup#include <IE.au3> #include <WinAPI.au3> #include <GUIConstantsEx.au3> ; #include <WinAPIEx.au3> #include <WindowsConstants.au3> _IEErrorHandlerRegister(_ErrFunc) Local $oIE = _IECreate("https://www.autoitscript.com/forum/") Local $oDoc = _IEDocGetObj($oIE) Local $oIE_hwnd = _IEPropertyGet($oIE, "hwnd") Local $oElement, $oElement_save, $aMousePos Local $aBrowserPos[6] ; x , y , width , height , x right , y bottom Local $aOverlayPos[4] ; coordinates of the overlay frame ; Create a Phantom window with a visible frame Local $aParentPos, $AlphaKey = 0xABABAB Local $iBorderColor = 0x00FF00, $iBorderThickness = 5 $hOverlay = GUICreate("", -50, -50, 10, 10, $WS_POPUPWINDOW, $WS_EX_LAYERED + $WS_EX_TOPMOST) ; transparent $Panel = GUICreate("", 48, 48, 10, 10, $WS_CHILD + $WS_VISIBLE, -1, $hOverlay) ; this new window becomes a child of $hOverlay window GUISetBkColor($iBorderColor, $hOverlay) GUISetBkColor($AlphaKey, $Panel) _WinAPI_SetLayeredWindowAttributes($hOverlay, $AlphaKey, 0, $LWA_COLORKEY) GUISetState(@SW_SHOW, $hOverlay) While WinExists($oIE_hwnd) $aMousePos = MouseGetPos() ; Now we get reference to the DOM object behind the mouse pointer $oElement = $oDoc.elementFromPoint($aMousePos[0] - $oIE.document.parentwindow.screenLeft, $aMousePos[1] - $oIE.document.parentwindow.screenTop) ConsoleWrite("################ Continuing the execution after exception ####################" & @CRLF) If IsObj($oElement) And $oElement <> $oElement_save Then $oElement_save = $oElement $aBrowserPos[0] = Int($oIE.document.parentwindow.screenLeft) ; X position on the desktop of the left edge of the browser $aBrowserPos[1] = Int($oIE.document.parentwindow.screenTop) ; Y position on the desktop of the top border of the browser $aBrowserPos[2] = Int($oIE.document.documentElement.clientWidth) ; Width of browser's client area $aBrowserPos[3] = Int($oIE.document.documentElement.clientHeight) ; Height of browser's client area $aBrowserPos[4] = $aBrowserPos[0] + $aBrowserPos[2] ; X position on the desktop of the right border of the browser $aBrowserPos[5] = $aBrowserPos[1] + $aBrowserPos[3] ; Y position on the desktop of the bottom border of the browser ; $oRect = $oElement.getBoundingClientRect() ; coordinates of the DOM object within the client area of the browser ; $aOverlayPos[0] = Int($oRect.left) + $aBrowserPos[0] ; X position of the left overlay border (absolute desktop coordinates) If $aOverlayPos[0] < $aBrowserPos[0] Then $aOverlayPos[0] = $aBrowserPos[0] ; if left border of the DOM obj is out of browser, overlay border stays anyway within the screen $aOverlayPos[1] = Int($oRect.Top) + $aBrowserPos[1] ; Y position of the top overlay border If $aOverlayPos[1] < $aBrowserPos[1] Then $aOverlayPos[1] = $aBrowserPos[1] ; if top border of obj is out of browser, overlay border stays anyway within the screen $aOverlayPos[2] = Int($oRect.right - $oRect.left) ; width of the obj If $aOverlayPos[0] + $aOverlayPos[2] > $aBrowserPos[4] Then $aOverlayPos[2] = $aBrowserPos[4] - $aOverlayPos[0] ; if obj's width is out of bounds, force the edge within the browser $aOverlayPos[3] = Int($oRect.bottom - $oRect.top) ; Height of the obj If $aOverlayPos[1] + $aOverlayPos[3] > $aBrowserPos[5] Then $aOverlayPos[3] = $aBrowserPos[5] - $aOverlayPos[1] ; stay within browser's bounds ; WinMove($hOverlay, "", $aOverlayPos[0], $aOverlayPos[1], $aOverlayPos[2], $aOverlayPos[3]) $aParentPos = WinGetPos($hOverlay) ; x, y, width, height WinMove($Panel, "", $iBorderThickness - 1, $iBorderThickness - 1, Int($aParentPos[2] - $iBorderThickness * 2), Int($aParentPos[3] - $iBorderThickness * 2)) EndIf WEnd ; User's COM error function. Will be called if COM error occurs Func _ErrFunc($oError) ; Do anything here. ;MsgBox($MB_SYSTEMMODAL, "_IEErrorNotify Status", "Notification now is " & _IEErrorNotify()) 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) $oError = 0 EndFunc ;==>_ErrFunc Link to comment Share on other sites More sharing options...
NRK Posted April 26, 2018 Author Share Posted April 26, 2018 I am using 64 bit windows 7 Enterprise edition Service pack1 with IE 11.0.9600.18977 and AutoIT version v3.3.14.3 Link to comment Share on other sites More sharing options...
Juvigy Posted April 27, 2018 Share Posted April 27, 2018 Put this in the beginning : #AutoIt3Wrapper_UseX64=Y Link to comment Share on other sites More sharing options...
Danp2 Posted April 27, 2018 Share Posted April 27, 2018 @Juvigy Can you explain how that will solve the OP's issue? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
NRK Posted April 27, 2018 Author Share Posted April 27, 2018 It did not solve the issue. Below is the code snippet after adding #AutoIt3Wrapper_UseX64=Y directive. #include <IE.au3> #include <WinAPI.au3> #include <GUIConstantsEx.au3> ; #include <WinAPIEx.au3> #include <WindowsConstants.au3> #AutoIt3Wrapper_UseX64=Y _IEErrorHandlerRegister(_ErrFunc) Local $oIE = _IECreate("https://www.autoitscript.com/forum/") Local $oDoc = _IEDocGetObj($oIE) Local $oIE_hwnd = _IEPropertyGet($oIE, "hwnd") Local $oElement, $oElement_save, $aMousePos Local $aBrowserPos[6] ; x , y , width , height , x right , y bottom Local $aOverlayPos[4] ; coordinates of the overlay frame ; Create a Phantom window with a visible frame Local $aParentPos, $AlphaKey = 0xABABAB Link to comment Share on other sites More sharing options...
Danp2 Posted April 27, 2018 Share Posted April 27, 2018 12 hours ago, NRK said: By adding _IEErrorHandlerRegister(), it intercepts the COM error and continues the loop, however after handling the error for around 30 times, it comes out the program with exit code 255. The only time the error occurs is when the you close the IE window, so I believe your analysis here is faulty. The ConsoleWrite you added only indicates that the code has continued running after the prior command, not that an error has occurred. I suspect that you are running out of memory / resources. When I ran your revised code, it looped over 1500 times without encountering an error. I did observed that memory usage was increasing as the script ran, but haven't tried to figure out why this is occurring. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Juvigy Posted April 27, 2018 Share Posted April 27, 2018 1 hour ago, Danp2 said: @Juvigy Can you explain how that will solve the OP's issue? I had similar issues with objects that was caused by a bug in AutoitxX86 version. Putting the line forces usage of X64bit and resolved my issues. Link to comment Share on other sites More sharing options...
junkew Posted April 28, 2018 Share Posted April 28, 2018 Try to reproduce with objcreate internetexplorer.application. Then you exclude at least if its caused by ie.udf itself. Try in excel vba with the object if you get same behavior. FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
NRK Posted April 28, 2018 Author Share Posted April 28, 2018 On 4/27/2018 at 4:49 PM, Danp2 said: The only time the error occurs is when the you close the IE window, so I believe your analysis here is faulty. The ConsoleWrite you added only indicates that the code has continued running after the prior command, not that an error has occurred. I suspect that you are running out of memory / resources. When I ran your revised code, it looped over 1500 times without encountering an error. I did observed that memory usage was increasing as the script ran, but haven't tried to figure out why this is occurring. The COM error "Bad Variable Type" came much earlier before I closed IE window. Idea behind the ConsoleWrite is to prove that after error is handled, the loop continues. In my machine, when I tested, the memory consumption did not increase beyond 2%. I don't think memory is an issue as there is no local variable defined inside the loop. Link to comment Share on other sites More sharing options...
NRK Posted April 28, 2018 Author Share Posted April 28, 2018 3 hours ago, junkew said: Try to reproduce with objcreate internetexplorer.application. Then you exclude at least if its caused by ie.udf itself. Try in excel vba with the object if you get same behavior. I do not have much experience in vba excel or objecreate, can you please share a sample code or outline so that I can elaborate it and test it. Link to comment Share on other sites More sharing options...
NRK Posted April 28, 2018 Author Share Posted April 28, 2018 On 4/27/2018 at 5:24 PM, Juvigy said: I had similar issues with objects that was caused by a bug in AutoitxX86 version. Putting the line forces usage of X64bit and resolved my issues. I am using IE 32 bit. Will that be the reason behind this issue? Does #AutoIt3Wrapper_UseX64=Y work fine with 32 bit version of IE? Link to comment Share on other sites More sharing options...
junkew Posted April 28, 2018 Share Posted April 28, 2018 No then you should put value to n FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets 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