1

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?

Leo
  • 5,013
  • 1
  • 28
  • 65

1 Answers1

0

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.

Max Young
  • 1,522
  • 1
  • 16
  • 42