.NET 以编程方式定位 ActiveX 控件中的文本框,修改其文本并提交
我有一个带有工具栏的 ActiveX 控件(Adobe PDF Reader)。该控件不公开通过工具栏可用的某些功能(主要是搜索功能)。我正在寻找一种方法以编程方式找到工具栏上的“搜索”字段,输入文本并调用搜索(相当于在此字段中按 Enter 键)。 最准确的方法是什么?找到了基于 System.Windows.Automation 命名空间的解决方案,但无法使其正常工作。
谢谢。
这是我尝试过的代码:
Dim pdfElement As AutomationElement = AutomationElement.FromHandle(AxAcroPDF1.Handle)
Dim condition As New AndCondition(New OrCondition(New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit), New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document), New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text)), New PropertyCondition(AutomationElement.IsTextPatternAvailableProperty, True))
Dim ac As AutomationElementCollection = pdfElement.FindAll(TreeScope.Descendants, condition)
For Each element As AutomationElement In ac
If element.Current.Name = "Find" Then
element.SetFocus()
SendKeys.Send("TESTSEARCH")
End If
Next
I have an ActiveX control (Adobe PDF Reader) with a toolbar. This control doesn't expose some functions available through toolbar (mainly search function). I'm looking for a way to programmatically locate Search field on the toolbar, enter the text and invoke search (equivalent of pressing Enter in this field).
What's most accurate way to make that? Found a solution based on System.Windows.Automation namespace, but couldn't get it to work correctly.
Thanks.
Here's the code I tried:
Dim pdfElement As AutomationElement = AutomationElement.FromHandle(AxAcroPDF1.Handle)
Dim condition As New AndCondition(New OrCondition(New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit), New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document), New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text)), New PropertyCondition(AutomationElement.IsTextPatternAvailableProperty, True))
Dim ac As AutomationElementCollection = pdfElement.FindAll(TreeScope.Descendants, condition)
For Each element As AutomationElement In ac
If element.Current.Name = "Find" Then
element.SetFocus()
SendKeys.Send("TESTSEARCH")
End If
Next
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
与您上一个问题的答案相同。零售自动化接口具有 FindText() 方法。我已经为您提供了 API 文档的链接。
Same answer as you previous question. The retail automation interface has the FindText() method. I already gave you the link to the API documentation.