How to find out where the cursor is in the WpfEdit field with CodedUI automation?

In the CodedUI WpfEdit class, there is a way to get the selected text, but I cannot find a way to get the cursor position when nothing is selected (i.e. the carriage index in the text). Is there anything available for the CodedUI platform?

My goal is to validate the cursor position in the text contained in the control.

+6
source share
2 answers

There is no codedui method for this, but try the following: add the link:

using System.Windows.Forms 

in the code where you need to get a coordinated moue type:

 Point p = new Point(Cursor.Position.X, Cursor.Position.Y); 

remember that this is not a relative position for the control, but a mouse position on the screen.

calculating the position of a point with respect to control should not be a big problem.

0
source

I'm not sure there is a way, and I would suggest that there is a different requirement than actually finding the cursor position.

If you are trying to paste some text, you can always copy the text to the test method, paste the text and write it back.

Or, if you do not need to do this, you can always use the Keyboard.SendKeys method to send the home command, and then any number of commands with arrows on the right to place the cursor where you want.

Can you tell us more about what exactly you need with the cursor position?

0
source

Source: https://habr.com/ru/post/984246/


All Articles