Windows UI Automation not showing all child elemen

2019-02-22 23:49发布

I have a TreeView control on my form, and I'm recursively going through the elements of another window starting with the window itself. I'm using this to find the elements:

getRecursiveElements(AutomationElement parent)
{
  children = parent.FindAll(TreeScope.Children, Condition.TrueCondition);

  foreach (AutomationElement child in children)
  {
    addToTreeView(child);
    getRecursiveElements(child);
  }
}

Generally speaking, the code works quite well in most cases. The tree is populated and I have a bit of other supporting code allowing me to double click, for example, an element in the tree-view and it will highlight that element on the target form.

The issue I'm having is that, while it generates an awesome tree, there are still some elements missing for certain target programs.

What possible reason could there be for this, and is there any way to get around it? If I call EnumChildWindows() from user32.dll will that have the same problem?

2条回答
SAY GOODBYE
2楼-- · 2019-02-23 00:19

Not all programs use separate windowed controls for all their logical children. Mostly this depends on the GUI framework used.

As an extreme example, Qt uses a single window for each top-level window. It then paints all the widgets on the form from the form's WM_PAINT message handler.

Programs that take this approach are typically impossible to automate through generic methods.

It sounds like you have encountered an application that uses some windowed controls but also uses custom controls with a single window for what appears to be multiple widgets. Again this is quite common.

查看更多
干净又极端
3楼-- · 2019-02-23 00:33

Could you give a better example of what fails? Thinking about the problem, it may be that the 'element' in the other form is being drawn manually, and so doesn't have distinct registered handles for everything.

查看更多
登录 后发表回答