即使我能够使用“名称"检索按钮,也无法单击它 [英] Unable to click a button even though I am able to retrieve it using the Name

查看:121
本文介绍了即使我能够使用“名称"检索按钮,也无法单击它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  var navigator = BonusAppControllers.EbsControl.CurrentApp.GetWindow("XWindow").Get(SearchCriteria.ByAutomationId("AnimatedExplorerNavigator"));
  AutomationElement dashboardElement = navigator.AutomationElement.FindFirst(TreeScope.Subtree,SearchConditionFactory.CreateForName("NavigateLink_1").AutomationCondition);
  var dashBoardBtn = new Button(dashboardElement, navigator.ActionListener);
  dashBoardBtn.Click();

我对于名称为NavigateLink_1的按钮有此代码.现在,当我运行它并对其进行调试时,我发现能够在dashBoardBtn变量中获取正确的按钮实例,但Click()函数无法正常工作.即使我尝试像使用Get(SearchCriteria.ByText("NavigateLink_1"))那样仅通过使用按钮名称来完成所有这些操作,我也会遇到相同的问题.我对同一组按钮的其他按钮部分尝试过相同的操作,但在这种情况下可以正常工作.

I have this code for the button with Name as NavigateLink_1. Now when i run this and debug it, I find that I am able to get the correct button instance in the dashBoardBtn variable but the Click() function isn't working. Even if i try to do all this just by using the button name as in using Get(SearchCriteria.ByText("NavigateLink_1")) I face the same problem. The same thing I tried with some other button part of the same group of buttons but it's working fine in that case.

任何人都可以建议我可能是什么问题.我正在使用White Framework和UI Spy作为我的应用程序的UI检查器

Can Anyone suggest me what could be the problem.I am using the White Framework and UI Spy as the UI inspector for my application

推荐答案

我没有使用White,但是我使用了本机UIA库.您偶尔会遇到的问题是,您将拥有一个可单击的对象,但是根据内部对单击的处理方式,您不一定可以使用InvokePattern来执行单击.可能就是这种情况.

I haven't used White, but I have used the native UIA libraries. The issue you'll occasionally run into with it is that you'll have an object that is clickable, but depending on how the click is being handled internally, you may not necessarily be able to use the InvokePattern to perform a click. That might be the case here.

作为替代,您可以使用一些代码将鼠标光标移到AutomationElement上,并使用P/Invoke发出单击.有点麻烦,但是当您遇到此问题时,它通常是最简单的选择.

As an alternative, you can use some code to move the mouse cursor over the AutomationElement and issue a click using P/Invoke. It's a bit of a hack, but it's often the simplest option when you run into this problem.

private const UInt32 MOUSEEVENTF_LEFTDOWN = 0x0002;
private const UInt32 MOUSEEVENTF_LEFTUP = 0x0004;

[DllImport("user32.dll")]
private static extern void mouse_event(UInt32 dwFlags, UInt32 dx, UInt32 dy, UInt32 dwData, IntPtr dwExtraInfo);

...
...

AutomationElement buttonToClick;

...
...

Cursor.Position = buttonToClick.GetClickablePoint();
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new IntPtr());
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new IntPtr());

这篇关于即使我能够使用“名称"检索按钮,也无法单击它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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