Page 1 of 1

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

Posted: 31 Jul 2015, 05:51
by serg
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:
http://www.autohotkey.com/board/topic/7 ... -09272012/
http://www.autohotkey.com/board/topic/7 ... 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

+z::
; 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%
return
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.

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

Posted: 13 Aug 2015, 02:59
by fump2000
Hi!
Please, can you post a complete example script for Chrome or IE?

I still do not understand the workings.

thx!
fump

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

Posted: 14 Aug 2015, 05:55
by Guest10
Can you post example scripts for Firefox? :geek: