Get name/state or activate any tab in a web browser

Post your working scripts, libraries and tools
Posts: 41
Joined: 21 Mar 2015, 05:33

Get name/state or activate any tab in a web browser

31 Jul 2015, 05:51

I want to share what I have just learned - how to get info or activate any tab in a browser. This method will probably work for most browsers, I tried it on few and it worked.
It is based entirely on posts/code by Jethrow. Since it took me some time to figure out how to do it even after reading Jethrow posts, I want to share this step by step guide, which might be helpful to other AHK newbies.

Big THANKS to Jethrow for Accessible Info Viewer and to Sean & Jethrow for Acc library.
(I know Jethrow abandoned Acc-Viewer in favor of UI-based tools, but it still works like a charm)

Acc Lib and Accessible Info Viewer will be needed: ... -09272012/ ... 012-09-20/

Open the Viewer and drag cross on top of the browser control where all tabs are located and see if in Acc Structure you can see names of tabs.
If you see tab names there, note name of Class(NN) of that control, and "Path" / "Child ID" on the bottom of the Viewer

Here is example for K-Meleon browser:
From the Viewer, I got tab control Class(NN) "ToolbarWindow322", Path "4", Child ID - 1,2,3... {tab numbers}

Code: Select all

; get hwnd of a browser-control where all tabs are located, you can get its name from Acc Info Viewer
ControlGet, hw1, hwnd,, ToolbarWindow322, ahk_class KMeleon Browser Window
hw2 = ahk_id %hw1%

Win := Acc_ObjectFromWindow(hw1)

; get number of tabs in KM-Browser, it will be the same as accChildCount in this case
n := Win.accChildCount

Loop, %n%
 tab_list .= Acc_Get("Name", "4", A_Index, hw2) "`t" Acc_Get("State", "4", A_Index, hw2) "`n"
msgbox %tab_list%
Active tab will have "Checked" state in this case

To activate particular tab, use this command:

Code: Select all

Win.accDoDefaultAction(A_Index)			;(inside of Loop above, where "A_Index" will be a tab number -  from 1 up to %Win.accChildCount%)
For some mysterious reason, if I assign "var := A_Index" (inside of Loop) and then "Win.accDoDefaultAction(var)" - it doesnt work!?
To get Value/Role, replace "Name" with "Value" or "Role" etc.
User avatar
Posts: 313
Joined: 04 Oct 2013, 17:31

Re: Get name/state or activate any tab in a web browser

13 Aug 2015, 02:59

Please, can you post a complete example script for Chrome or IE?

I still do not understand the workings.

Posts: 578
Joined: 01 Oct 2013, 02:50

Re: Get name/state or activate any tab in a web browser

14 Aug 2015, 05:55

Can you post example scripts for Firefox? :geek:

Return to “Scripts and Functions”

Who is online

Users browsing this forum: BillyJ88, Bing [Bot], Kellyzkorner_NJ, Xtra and 49 guests