最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - System Ui Automation. Can't find rows in table - Stack Overflow

programmeradmin3浏览0评论

I try to programmatically read some table rows from a Windows application using System.Windows.Automation in a C# console app.

The rows are inside a table that is inside a dialog. I'm using Windows accessibility insight which can find the row and show me the tree structure.

I'm able to find the table but not the rows. The only children I found under the table is the scrollbar and its buttons.

I've also tried to invoke the scroll to reload the table in case it's been virtualised.

The grid control:

The row:

Code:

  static void Main(string[] args)
  {
      var appWindow = AutomationElement.RootElement.FindFirst(
      TreeScope.Children,
          new PropertyCondition(AutomationElement.NameProperty, appName));

      if (appWindow != null)
      {
           // Find the dialog
           var dialog = appWindow.FindFirst(TreeScope.Descendants,
           new PropertyCondition(AutomationElement.NameProperty, "Plotdata - Test"));

           if (dialog != null)
           {
               var tables = dialog.FindAll(TreeScope.Descendants, new 
               PropertyCondition(AutomationElement.ControlTypeProperty, 
               ControlType.Table));
     
               if (tables != null)
               {
                  foreach (AutomationElement table in tables)
                  {
                     Console.WriteLine(table.Current.Name);
                     Console.WriteLine(table.Current.ControlType.ProgrammaticName);

                     AutomationElementCollection rows = 
                           table.FindAll(TreeScope.Descendants,
                           new PropertyCondition(AutomationElement.ControlTypeProperty, 
                           ControlType.Custom)); //The row is ControlType.Custom. Also 
                           tried common table items types
                  }
               }
           }
      }
 }
发布评论

评论列表(0)

  1. 暂无评论