Maina Ninnu Maina Ninnu - 4 months ago 98
C# Question

CodedUi:Mouse click with coordinates

How to click on a specific portion of a button in all screen types? I have a button with dropdown values, I need to click on the downarrow image, I tried below code:

Mouse.click(someBtn,new Point(250,45));


This works in my screen, this clicks somewhere else on desktops since axis changes. Suggest some workarounds or solutions.

Answer

Try giving a position relative to the control that is being clicked, instead of an absolute point, use this property:

 uitestcontrol.BoundingRectangle

like this:

var btnPosition= someBtn.BoundingRectangle

and then select the position you want to click based on the controls current position.

for example:

Point relativePoint = new Point(btnPosition.X + 40, btnPosition.Y - 40);
Mouse.click(someBtn,relativePoint );