Jump to content
Sign in to follow this  

How to Select an IE Tab and to Get the Selected IE Tab?

Recommended Posts


In this script below, I'm trying to:

  1. Create an Internet Explorer, and to navigate it to a blank page.
  2. Create a new tab with a blank page.
  3. Create another tab again. (Please don't ask me why 'cause it's just a test.)
  4. Get all the 3 object variables pointing to those 3 InternetExplorer Objects.
  5. And to test to select the tab two, then to select the tab one which is fail!
#include <IE.au3>

$oIE = _IECreate("about:blank", 0, 1, 1, 1)

__IENavigate($oIE, "about:blank", 0, 0x800)

__IENavigate($oIE, "about:blank", 0, 0x800)

Local $oTabs[1]

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


_IEAction($oTabs[1], "focus")


_IEAction($oTabs[0], "focus")

Could you please tell me how to fix that AU3 code to select and not to WinActivate() the tab because as far as I know, activating tab will make this tab at the front of the your Windows screen which I do not want because I want to automate the IE even I'm working on a different application.

Now, this is my second question! How can I get the current selected tab on a web browser, specially in Internet Explorer, even I'm in another application to read that tab's text using the _IEBodyReadText() libfunction? Thanks for any help!

Share this post

Link to post
Share on other sites

This is how I get the IE object for the currently active tab:

; Function Name:    _IEGetActiveTab()
; Description:      Retrieve the IE Window Object of the currently active tab
; Parameter(s):     None
; Requirement(s):   AutoIt3 V3.2 or higher
;                   On Success  - Returns an object variable pointing to the IE Window Object
;                   On Failure  - Returns 0 and sets @ERROR
;                   @ERROR      - 0 ($_IEStatus_Success) = No Error
;                               - 7 ($_IEStatus_NoMatch) = No Match
; Author(s):        Dan Pollak
Func _IEGetActiveTab()
Local $hwnd, $i, $title, $oIE
    ; get first IE instance
    $oIE = _IEAttach ("", "instance", 1)

    If @error = $_IEStatus_Success Then
        ; get window title
        $hwnd = _IEPropertyGet($oIE, "hwnd")
        $title = WinGetTitle($hwnd)

        $oIE = _IEAttach($title, "windowtitle")

    Return $oIE
  • Like 1

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.