如何在未实现任何模式的情况下操纵控件? [英] How to manipulate a control without any pattern implemented?

查看:88
本文介绍了如何在未实现任何模式的情况下操纵控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过UIAutomation为我们的项目实施自动化测试.但是许多控件并不可靠,并且也没有为该控件实现适当的模式.在这种情况下,应该如何通过 UIAutomation框架来操纵控件?

I'm trying to implement the automation test via UIAutomation for our project. But lots of the controls are not standrad, and proper patterns are also not implemented for that controls. How should I to manipulate the controls via UIAutomation framework in this case?

例如,我们产品中的按钮是通过窗格实现的,而调用的模式也没有实现.我应该如何点击按钮? (为避免在测试计算机上安装VS,我不想在Microsoft.VisiualStudio.TestTools.UITesting命名空间中使用Mouse.Click())是否有办法仅使用UIAutomation框架或.net框架中嵌入的其他方法来做到这一点?提前致谢! (如果实施了正确的模式,则下面的代码将起作用.作为新用户,我无法将屏幕快照发布供您参考,对不起!)

For example, a button in our product is implemented via a Pane, and the invoked pattern is not implemented as well. How should I click the button? (To avoid installing VS on the test machine, I don't want to use Mouse.Click() in Microsoft.VisiualStudio.TestTools.UITesting namespace) Is there a way to do that only using UIAutomation framework or something else embedded in .net framework? Thanks in advance! (If the proper pattern is implemented, Below code will work. And as a new user, I cannot post the screenshot for your reference, sorry!)

object temp = null;
if (btnTest.TryGetCurrentPattern(InvokePattern.Pattern, out temp))
{
    InvokePattern btnTestPattern = temp as InvokePattern;
    btnTestPattern.Invoke();
}

推荐答案

最好的办法是,如果那些实施该系统的人会

The best thing would be, if those guys who implement the system would implement server-side UIA provider to their UI Elements!

但是通常这是不可能的...,我使用了以下解决方法(至少用于单击/切换):

But often that's not possible..., I used the following workaround (at least for clicking/toggling):

AutomationElement yourAE = ...// some code to find the right AutomationElement (AE)
clickablePoint = yourAE.GetClickablePoint();

BoundingRectangleProperty也可能有帮助

如果您收到该可点击的积分,则可以使用

If you receive that clickable point you can use

System.Windows.Forms.Cursor.Position = new System.Drawing.Point((int)clickablePoint.X, (int)clickablePoint.Y);

移至该位置,然后通过 InputSimulator 或某些win32(user32.dll)单击它命令. (注意:当然,您也可以使用InputSimulator或win32来移动鼠标-但是当InputSimulator出现在具有不同位置或分辨率的多个屏幕上时,我遇到了一些问题-因此Cursor.Position是最简单的方法,也很可靠)

to move to the location, and than click it via InputSimulator or some win32 (user32.dll) commands. (note: of course you can also use InputSimulator or win32 to move the mouse - but I had some problems with the InputSimulator when it came to several screens with different locations or resolutions - so Cursor.Position was the easiest approach, which is also very reliable)

这篇关于如何在未实现任何模式的情况下操纵控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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