使用反射实例化自动化元素上的模式 [英] Using reflection to instantiate pattern on an automationelement

查看:87
本文介绍了使用反射实例化自动化元素上的模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用反射对给定的自动化元素执行指定的操作,例如,用户提供了该元素以及他们希望对其执行的操作.例如. AutomationAgent.excute(开始会议按钮","InvokePattern").

Hi, I'm trying to use reflection to perform a specified action on a given automation element, for example the user supplies the element and the action they would like performed on it. eg. AutomationAgent.excute("Start Meeting button", "InvokePattern").

部分(a)轻松地动态查找自动化元素,我只是首先使用提供的条件进行查找.

Part (a) finding the automation element dynamically is easy, I simply do a find first using the condition supplied.

(b)部分0创建正确的模式并调用它要困难一些.我正在尝试使用c#反射来实例化模式类(例如InvokePattern),并在自动化元素上进行分配/调用,但是我无法弄清楚它的使用寿命. 我!

Part (b) 0 creating the correct pattern and invoking it is a bit more difficult. I'm trying to use c# reflection to instantiate the pattern class (eg InvokePattern) and assign/invoke it on the automation element, but I can't figure it out for the life of me! 

由于某种原因我无法实例化模式类(createInstance表示未定义构造函数),并且没有构造函数.

I can't instantiate a pattern class for some reason (createInstance says no constructor defined) and there is no constructor.

任何帮助将不胜感激.

谢谢.

 

 

推荐答案

罗比,

我不能说我曾经通过反射使用过这些类,但是我可以解释构造函数的问题.您实际上并不是自己构造InvokePattern的.相反,您致电 在AutomationElement上获取GetCurrentPattern ,然后将对象转换回InvokePattern.(我链接的页面上有一个代码示例.)假设您可以通过反射进行此类投射,那么您应该已经准备就绪.

I can't say I've ever used those classes via Reflection, but I can explain the constructor issue.  You don't actually construct InvokePattern yourself.  Instead, you call GetCurrentPattern on the AutomationElement and then cast the object you get back into InvokePattern.  (There's a code sample on the page I linked.)  Assuming you can do such casting through Reflection, you should be all set.

谢谢,
迈克尔

Thanks,
Michael 


这篇关于使用反射实例化自动化元素上的模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆