Jump to content

Please Help Me Get the Object Variables Pointing to the IE Tabs with an Array


Recommended Posts

This is my test code:

#include <IE.au3>

Local $oIE

$oIE = _IECreate("http://www.example1.com/", 0, 1, 1, 1)

__IENavigate($oIE, "http://www.example2.com/", 0, 0x800)

__IENavigate($oIE, "http://www.example3.com/", 0, 0x800)

Local $oTabs[1], $i = 1

While 1
   $oTabs[$i - 1] = _IEAttach($oIE, "instance", $i)
   If @Error = $_IEStatus_NoMatch Then
      ReDim $oTabs[$i - 1]
      ExitLoop
   EndIf
      ReDim $oTabs[$i + 1]
      $i += 1
WEnd

Sleep(3000)

Local $oText

$oText = _IEBodyReadText($oTabs[0])
MsgBox(0, "Tab 1", $oText)

$oText = _IEBodyReadText($oTabs[1])
MsgBox(0, "Tab 2", $oText)

$oText = _IEBodyReadText($oTabs[2])
MsgBox(0, "Tab 3", $oText)

At the end of the code, you will see that I'm trying to input the text of the 1st first tab which is succeed, but when I try to check if the text reading on the 2nd tab with the _IEBodyReadText($oTabs[1]) libfunction and on the 3rd tab with _IEBodyReadText($oTabs[2]) they are fail.

Could you please guide me how to get the object variables pointing to the tabs of the Internet Explorer, to use for _IEBodyReadText() libfunction? Thank (Like) you!

Edited by Servant
Link to comment
Share on other sites

On my yesterday's thread, I'm asking how to select the tab on the Internet Explorer with many tabs, and to get the object variable pointing to the current selected tab.

While in this thread, I want to get the object variables pointing to all the tabs on the IE. Now I know, on my previous thread, in the step no# “4. Get all the 3 object variables pointing to those 3 InternetExplorer Objects.” is not working. That's why I'm asking it now.

Link to comment
Share on other sites

In both instances, your script will work if you add a delay before gathering the IE objects. Place the command "Sleep(3000)" after the final IENavigate command and then run the script again.

I suspect that the issue is due to the fact that the websites haven't loaded or the objects haven't fully instantiated. Therefore, you aren't getting accurate results when scanning through the IE instances. You could also use the Ubound() function to check the size of the array, which would have helped in diagnosing this issue.

Link to comment
Share on other sites

Actually, I hate the Sleep() function. Is there anything I can do other with this function?

And also other than these WinWait() lines:

...

__IENavigate($oIE, "http://www.example3.com/", 0, 0x800)

WinWait("Tab 2's Title")
WinWait("Tab 3's Title")

...

And I'm pretty sure that I cannot use the _IELoadWait($oIE) function 'cause I've tested it. It works only for the first tab of the Internet Explorer.

Edited by Servant
Link to comment
Share on other sites

Try this:

#include <IE.au3>

ConsoleWrite("Launching initial instance" & @CRLF)
$href = "www.autoitscript.com"
$oIE = _IECreate($href)

ConsoleWrite("Loading 2nd tab" & @CRLF)
$href = "www.yahoo.com"
OpenNewTab($oIE, $href)

ConsoleWrite("Loading 3rd tab" & @CRLF)
$href = "www.google.com"
OpenNewTab($oIE, $href)

ConsoleWrite("Collecting IE instances" & @CRLF)

Local $oTabs[1]

Local $i = 1
While 1
    ConsoleWrite("Attaching instance " & $i & @CRLF)
   $oTabs[$i - 1] = _IEAttach($oIE, "instance", $i)
   If @Error = $_IEStatus_NoMatch Then
      ReDim $oTabs[$i - 1]
      ExitLoop
   EndIf
      ReDim $oTabs[$i + 1]
      $i += 1
WEnd

ConsoleWrite("$i = " & $i & @CRLF)

ConsoleWrite(UBound($oTabs) & " instances detected!" & @CRLF)

For $i = 0 To UBound($oTabs) - 1
    ConsoleWrite("Getting text from instance " & $i + 1  & @CRLF)
    $oText = _IEBodyReadText($oTabs[$i])
    MsgBox(0, "Tab " & $i + 1, $oText)
Next

Func OpenNewTab($oIE, $href)

Const $navOpenInNewTab = 0x0800
Const $navOpenInBackgroundTab = 0x1000

Local $oIE2, $iTimer

$oIE.navigate ($href, $navOpenInNewTab )

ConsoleWrite("Waiting for instance to be visible" & @CRLF)

    $iTimer = TimerInit()

    Do
        $oIE2 = _IEAttach($href, "URL")

        If @error = 0 Then
            ConsoleWrite("Instance found; performing _IELoadWait" & @CRLF)
            _IELoadWait($oIE2)
            ExitLoop
        EndIf
    Until TimerDiff($iTimer) > 30000
EndFunc
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...