Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 565
Maina Ninnu Avatar asked Sep 11 '26 02:09

Maina Ninnu


2 Answers

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 );
like image 143
barakcaf Avatar answered Sep 13 '26 15:09

barakcaf


I had this problem and I found the same solution as Niels did in the comments above. If you do the same however, what you are actually doing is ignoring the UI elements and you are clicking on a known point on the screen. Your window must not move for this to work. So the solution Niels and myself have used can be done in 1 line of code (no need for the Bounding rectangle or someBtn) like this...

Mouse.Click(new Point(575, 920));

The risk is that your window moves but as the Coded UI has an unclickable point for some reason I can't see any other way. This line is in a method in my UIMap.cs (having moved the method there by right clicking on the method in the UIMap.uitest and choosing "Move Code to UIMap.cs"). So I agree with Niels but if you do that, the rest of the code in that answer is not being used!

If you don't know about Moving Code to UIMap.cs then read about it, basically if you change system generated code without moving it then your code will be overwritten when you build next, leaving you wondering where your code went and why your test stopped working. Don't ask me how I know this!

like image 28
Ewan Avatar answered Sep 13 '26 15:09

Ewan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!