简体   繁体   中英

Get Caret position with TestStack.White

I am using White to get a Microsoft Word Window and the Document as a TextBox like this:

Application a = Application.Attach(0x0000AC34);
Window w = a.GetWindow("Document1 - Word", InitializeOption.WithCache);
TextBox doc = w.Get<TextBox>(SearchCriteria.ByControlType(ControlType.Document));

Is there a way to get the position of the caret? I am interested in both, the screen coordinates and the position within the text.

Ideally, I am looking for something in White .

If not, I know I can rely on AutomationElement and TextPattern ie.

TextPattern tp = doc.AutomationElement.GetCurrentPattern(TextPattern.Pattern) as TextPattern;
TextPatternRange[] selectionRanges = tp.GetSelection();
// etc...

Is there any drawbacks in doing so? Are there better options I should consider?

Is there a way I can access the IUIAutomationTextPattern2 interface?

You would not be able to do this in TestStack.White because TestStack.White only wraps the managed UIAv2 API. With FlaUI you would be able to do this because they have a package for both UIAv2 and UIAv3. Here is the wrapper they wrote around the UIAv3 COM dll.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM