开发者

.NET programmatically locate text box in ActiveX control, modify its text and submit it

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 el开发者_JAVA技巧ement As AutomationElement In ac

    If element.Current.Name = "Find" Then
        element.SetFocus()
        SendKeys.Send("TESTSEARCH")
    End If

Next


Same answer as you previous question. The retail automation interface has the FindText() method. I already gave you the link to the API documentation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜