简体   繁体   English

使用TestStack.White获得Caret职位

[英]Get Caret position with TestStack.White

I am using White to get a Microsoft Word Window and the Document as a TextBox like this: 我正在使用White获取Microsoft Word窗口和文档作为文本框,如下所示:

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 . 理想情况下,我正在寻找White东西。

If not, I know I can rely on AutomationElement and TextPattern ie. 如果没有,我知道我可以依靠AutomationElementTextPattern即。

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? 有没有一种方法可以访问IUIAutomationTextPattern2接口?

You would not be able to do this in TestStack.White because TestStack.White only wraps the managed UIAv2 API. 您将无法在TestStack.White中执行此操作,因为TestStack.White仅包装了托管的UIAv2 API。 With FlaUI you would be able to do this because they have a package for both UIAv2 and UIAv3. 使用FlaUI,您将能够执行此操作,因为它们具有UIAv2和UIAv3的软件包。 Here is the wrapper they wrote around the UIAv3 COM dll. 这是他们围绕UIAv3 COM dll编写的包装

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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