0

Using UIAutomation on windows Forms, I'm trying to retrieve any control under mouse on a specific form. The goal is to work on controls of an app, retrieving and acting on them.

The problem I'm facing since so many times is that I can't find a toolstripbutton. Everytime I'm getting a pane (not parent nor child of the toolstripbutton I want, but parent's sibling).

This is the toolstripbutton I want to retrieve : screenshot 1.

The same control but in Inspect.exe (highlighted: the control I'm getting) : screenshot 2

I though that it was because of z order of the controls, then I tried using sibling controls, for controls where their bounds contains the mouse (for getting all controls under the cursor anyway their z order). That fails because the toolstripbutton isn't retrieved.

I currently use UIAutomation and not CodedUI, because I need to run a custom program which retrieve controls and executes automatic tests on a specific server, but I actually have the Visual Studio Enterprise 2017 licence installed on my machine, but a second licence (for the server) and a third licence for a colleague for work with me on it would be a bit expensive.

Remembering that the programs have to retrieve dynamically the controls under the mouse, may someone gives me any idea which can help me to investigate deeper ?

Thanks & Greetings

Method used:

var aimed = AutomationElement.FromPoint(new System.Windows.Point(Cursor.Position.X, Cursor.Position.Y));
Armali
  • 18,255
  • 14
  • 57
  • 171

1 Answers1

0

Solved by work around.

I made a recursive method that search deeper in the children for controls which contains the mouse (BoundingRectangle.Contains` method). In that way, I can find the controls within the toolstrip.

But AutomationElement.FromPoint method doesn't search inside the toolstrip.