user1244069
user1244069

Reputation: 95

Microsoft Automation UI mouse click on a given position

I am developing a C# console application that will open up an application and do some stuff there. I am able to launch the app and login to app. I need to do some mouse click operation on specific positions though but could not find how to do it. Is it possible to simulate it? I must use the position because I need what I want to do is not just clicking on a button or textbox. I need to do a right click on main window and choose something from the opening menu. I am not sure there is a way to do it with Microsoft Automation UI.

Thanks in advance.

Upvotes: 3

Views: 8031

Answers (2)

unickq
unickq

Reputation: 3350

Download Microsoft.TestApi from Nuget.

using Microsoft.Test.Input;
using System.Drawing;

Mouse.MoveTo(new Point(1000, 1000));
Mouse.Click(MouseButton.Right);

Also, you can use Teststack.White for such automation purposes.

Upvotes: 5

Rowbear
Rowbear

Reputation: 1669

Microsoft.TestApi should be able to click on a coordinate you provide. Take a look at the Mouse class' MoveTo method.

You'll probably have to get the coordinates via WinAPI's GetClientRect method though. Alternatively, you can use the TestApi in conjunction with UIAutomation as you were intending to use. Get the AutomationElement of your launched process by getting the window handle, then you can navigate the visual tree with UIAutomation, and use GetClickablePoint to get a Point object that you can pass to the TestApi's Mouse.MoveTo() method.

Upvotes: 2

Related Questions