Note: The UI Automation library is currently only compatible with 64bit AHK.
I've been wanting a UIAutomation library to accomplish such tasks, because it allows you to query an elements descendants based on a given criteria. Since AFAIK there isn't a UIA library being actively developed, I decided to write a quick function using my partially developed UIA library. I purposefully wrote this function in a noobie-friendly (relatively speaking) way to generate understanding & inspiration.I wrote: There is no direct HTML DOM method for activating a specific IE tab, that I'm aware of.
However, ACC (or better yet, UIA) provides a way of accomplishing this by accessing the tab element, then calling DoDefaultAction (the DefaultAction being Press). The problem with this method is finding a way to access the tab element that doesn't change with each new release of IE.
This function was developed using Internet Explorer 11, but should be compatible with any version of Internet Explorer that has tabs (7+). I would like to hear results from others using different versions of Internet Explorer.
This function requires UIA_Interface.ahk. The TabName parameter is case-sensitive:
Code: Select all
TabActivate(TabName, WinTitle) {
;~ Set Constants / Static Variables
static UIA_ControlTypePropertyId := 30003
, UIA_NamePropertyId := 30005
, TabItem := 50019
, VT_I4 := 3
, VT_BSTR := 8
, TreeScope_Descendants := 0x4
, uia := UIA_Interface()
, Condition1
;~ Get Internet Explorer UIA Element
WinGet, hwnd, ID, %WinTitle%
ie := uia.ElementFromHandle(hwnd)
;~ Set Conditions to find sub-element (TabItem)
if Not Condition1
Condition1 := uia.CreatePropertyCondition(UIA_ControlTypePropertyId, TabItem, VT_I4)
Condition2 := uia.CreatePropertyCondition(UIA_NamePropertyId, TabName, VT_BSTR)
AndCondition := uia.CreateAndCondition(Condition1,Condition2)
;~ Query for the first matching sub-element
tab := ie.FindFirst(AndCondition, TreeScope_Descendants)
;~ Access the Legacy Pattern
;~ Legacy Pattern is similar to the Accessible Interface, which has the DoDefaultAction method (Press)
legacy := tab.GetCurrentPatternAs("LegacyIAccessible")
legacy.DoDefaultAction()
}
Note: after posting this, I realized this works with FireFox as well & updated the thread title.