WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

System_Window_Automation

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Use System.Windows.Automation to List Chrome Tabs

 Keywords:  System.Windows.Automation Chrome UIAutomationClient UIAutomationTypes ControlType PropertyCondition Chrome_WidgetWin_1

  ;******************************************************************************************************************************
  ; Purpose: List Chrome Browser Tab Titles
  ;
  ; Author: kdmoyers (Kirby Moyers)
  ; Date: Monday, December 20, 2021
  ;*******************************************************************************************************************************
  
  ; Load required assemblies.
  ObjectClrOption("useany","UIAutomationClient")
  ObjectClrOption("useany","UIAutomationTypes")
  ObjectClrOption("useany","System")
  
  ; Search scope enumerated values.
  enumScope  =  ObjectClrNew("System.Windows.Automation.TreeScope")
  
  ;  Get access to the desktop window which is the parent of all other windows.
  objUiElement = ObjectClrNew("System.Windows.Automation.AutomationElement")
  objUiRoot = objUiElement.RootElement
  
  ; Instantiate a property condition for an Chrome window.
  objPropCon1 =  ObjectClrNew("System.Windows.Automation.PropertyCondition", objUiElement.ClassNameProperty, "Chrome_WidgetWin_1")
  
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;; Find the first such window under the desktop
  
  ; set scope to "children"
  nElement  = enumScope.Children
  Scope = ObjectClrType("System.Windows.Automation.TreeScope",nElement)
  
  ; Find all of those under the desktop.
  objChromeArr = objUiRoot.FindAll(Scope,objPropCon1)
  
  ; for each one...
  ForEach objChrome In objChromeArr
  
      ; get the main window title
      maintitle = objChrome.GetCurrentPropertyValue(objUiElement.NameProperty)
  
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      ; Find the all the tabitem type controls in chrome
  
      ; this is the "types" of controls
      ConType = ObjectClrNew("System.Windows.Automation.ControlType")
  
      ; this is a "condition"
      searchCon =  ObjectClrNew("System.Windows.Automation.PropertyCondition", objUiElement.ControlTypeProperty, ConType.TabItem);
  
      ; this is a "scope"
      nElement  = enumScope.Descendants
      Scope = ObjectClrType("System.Windows.Automation.TreeScope",nElement)
  
      ; Find that window.
      objArr = objChrome.FindAll(Scope,searchCon)
  
      lis = 'Main Window title="':maintitle:'"':@lf:@lf
      ii = 0
      ForEach item In objArr
          x = item.GetCurrentPropertyValue(objUiElement.NameProperty)
          ii = ii + 1
          lis = ItemInsert(ii:': ':x, -1, lis, @lf)
      Next
  
      Message("Chrome tabs",lis)
  
  Next
  
  Exit
  

Article ID:   W18543
Filename:   Use System.Windows.Automation to List Chrome Tabs.txt
File Created: 2021:12:23:09:44:24
Last Updated: 2021:12:23:09:44:24