Sign in to follow this  
Followers 0
van_renier

_IE functions, losing reference to object variable of an InternetExplorer.Application object

3 posts in this topic

Could someone help me understand why I'm losing the object for certain _IE  user-functions (those included with Au3 v3.3.10.2)

#include <IE.au3>   ; Required for automatically entering login credentials to app manager
GLOBAL $oIE
$oIE = _IECreate("about:blank", 1)
; _IEQuit ($oIE)   ; _IEQuit line HERE, it work, closing the browser...
ConsoleWrite ("===============================" & @CRLF )
If WinExists ( "Blank Page - Windows Internet Explorer") <> 1 then
   While WinExists ("Blank Page - Windows Internet Explorer") <> 1
      sleep ( 500 )
   WEnd
EndIf
sleep ( 1200 )
ConsoleWrite ("===============================" & @CRLF )
; _IEQuit ($oIE)   ; _IEQuit line HERE, it work, closing the browser...
ConsoleWrite ('This is where the object, $oIE, gets broken/lost' & @CRLF )
   _IENavigate( $oIE, "http://www.msn.com" )
   sleep (3000)
ConsoleWrite ("===============================" & @CRLF )
sleep ( 5000 )
_IEQuit ($oIE) ; HERE FAILS, console error: "--> IE.au3 T3.0-1 Error from function _IEQuit, $_IEStatus_InvalidObjectType"
exit

In the above script, there are 3 lines with _IEQuit. The 1st 2 are commented out, but they work with closing the browser fine, but the 3rd line, fails to close out the browser window.

(I'm not wanting to close out the browser window, but I was trying to figure out why subsequent calls lose the object variable reference of $oIE. Using _IEQuit seemed to be the easiest way to ensure we were attached to the same browser window.

I've also noticed that using the above script, after the script exits (with the 3rd _IEQuit line intact), since the browser window is still open, if I try and enter any URL into the adress bar, pressing enter then causing a new browser window to open up.

Any suggestions on why the object reference is getting broken?

Thanks,

Van

 

Share this post


Link to post
Share on other sites



Tried running the script you posted, and it worked like it should, here is the console output:

--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
--> IE.au3 T3.0-1 Warning from function _IEAttach, $_IEStatus_NoMatch
===============================
===============================
This is where the object, $oIE, gets broken/lost
===============================
+>15:24:18 AutoIt3.exe ended.rc:0
+>15:24:18 AutoIt3Wrapper Finished..
>Exit code: 0    Time: 14.827

 

The issue you are referring to (pressing enter then causing a new browser window to open up.) might be caused by IE itself, not AutoIt

Share this post


Link to post
Share on other sites

Have you seen >this post? Can't tell if this is the issue with the limited details you supplied...

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • Faalamva
      By Faalamva
      Hello,
      Let's take a simple example to illustrate my case.
      I open a webpage with the command _IECreate and I parse all its elements :
      #include <IE.au3> $oIE = _IECreate("http://www.york.ac.uk/teaching/cws/wws/webpage1.html") $oElements = _IETagNameAllGetCollection($oIE) For $oElement In $oElements ConsoleWrite("Tagname: " & $oElement.tagname & @CRLF & "Id: " & $oElement.id & @CRLF & "InnerText: " & $oElement.innerText & @CRLF & "--------------------------------" & @CRLF) Next Now let's imagine I simulate a click with MouseClick to the link "lesson two" at the bottom of this webpage. A new webpage will open :
      http://www.york.ac.uk/teaching/cws/wws/webpage2.html
      I'd like to get the elements (tagname, id, innertext) of this new webpage, just like I got them for the first webpage. But for this, I presume I would have to get a new $oIE2 Object variable of an InternetExplorer.Application, in order to be able to use the _IETagNameAllGetCollection once again.
      How am I supposed to do this ?
      Thank you !
       
    • Faalamva
      By Faalamva
      Hi,
      I'm using the IE.au3 library to parse elements in a webpage and get their (x,y) coordinates.
      Main commands I'm using are :         
      $oIE = _IECreate($myWebPage) $oElements = _IETagNameGetCollection($oIE, "label") $windowleft = $oIE.document.parentwindow.screenLeft $windowtop = $oIE.document.parentwindow.screenTop $oElementPosX = $windowleft + _IEfindPosX($oElement) $oElementPosY = $windowtop + _IEfindPosY($oElement) Now things become a bit tricky when i simulate a scroll in my webpage :
      $oIE.document.parentwindow.scroll(0, $myScrollY) Because once this is done, the coordinates of the elements are still what they were before the scroll.
      I can manage this problem by keeping track of the number of pixels I have scrolled, and compute the new "real" ($oElementPosX, $oElementPosY).
      But I'm pretty sure there's a more efficient / more elegant way to do it.
      What's more in some situations, when I click some controls in the webpage, the webpage adds new elements and shifts the controls below by a random number of pixel, so my workaround can't be used...
      So here's my question : Is there a way to "refresh" the calculation of label coordinates ($oElementPosX, $oElementPosY) after a scroll ?
      Thank you !
      EDIT : I forgot to post the _IEfindPosX and _IEfindPosY functions (found somewhere on this forum) :
      Func _IEfindPosX($o_object) Local $curleft = 0 Local $parent = $o_object If IsObj($parent) Then While IsObj($parent) $curleft += $parent.offsetLeft $parent = $parent.offsetParent WEnd Else Local $objx = $o_object.x If IsObj($objx) Then $curleft += $objx EndIf Return $curleft EndFunc Func _IEfindPosY($o_object) Local $curtop = 0 Local $parent = $o_object If IsObj($parent) Then While IsObj($parent) $curtop += $parent.offsetTop $parent = $parent.offsetParent WEnd Else Local $objy = $o_object.y If IsObj($objy) Then $curtop += $objy EndIf Return $curtop EndFunc  
    • sqa
      By sqa
      I am really stuck with this.
      #include<IE.au3>
      local $oIE = _IEAttach("Application")   ; the name of Tab
      local $oForm = _IEFormElementGetObjByName($oIE, "lastName")   ; "lastName" - <input name="lastName" class...>
       
      running it,, there is an error: _IEFormElementGetObjByName, $_TESTATUS_InvalidObjectType
      What's wrong?
    • orichec
      By orichec
      Hello,
      I'm trying to save source of a particular webpage using its URL. When i tried to save source code using following command it works fine
      $IE = _IECreate( 'www.example.com', 0, 0 )
      But my problem is different I've saved different URL in my excel sheet, that's why, I tried to use "$IE" command in this way;
      $URL = _Excel_RangeCopyPaste($oWorkbook1.Activesheet, "C1")
      $IE = _IECreate($URL, 0, 0 )
      But It's unable to fetch source codes using URL placed in excel sheet 1 at cell No. "C1".
      Please guide me what's wrong with my codes and how can I make it possible to use URL placed in excel sheet instead of copying URL every time in "_IECreate" command.
      Thanks
      #RequireAdmin #include <Excel.au3> #include <IE.au3> #include <String.au3> #include <Array.au3> Local $oExcel = _Excel_Open() Local $oWorkbook1 = _Excel_BookOpen($oExcel, @ScriptDir & "\Software.csv", True) $file = fileopen(@scriptdir & "\source01.txt", 10) ;------------Below Command is not working--------------------- $URL = _Excel_RangeCopyPaste($oWorkbook1.Activesheet, "C1" ;------------String $IE unable to fetch data from URL available in excel sheet at cell No. "C1"--------------------- $IE = _IECreate($URL, 0, 0 ) $source = _IEDocReadHTML($IE) FileWrite($file, $source)  
    • Dgameman1
      By Dgameman1
      My program is super simple with only 2 lines of code.
      #include <IE.au3> $Site = _IECreate("www.google.com", 0, 1, 1) I'm just trying to open up a browser that goes to google.com
      The issue with this is that whenever I try and run the program, I get this error
      Not sure how to go about fixing this issue?