编码ui:另一个控件正在阻塞该控件

本文关键字:控件 另一个 编码 ui | 更新日期: 2023-09-27 18:04:53

我正在尝试使用CodedUI自动化桌面应用程序,当我尝试点击按钮时,我正在获得以下错误。请给我一个解决办法。

{"Another control is blocking the control. Please make the blocked control visible and retry the action. Additional Details: 
 TechnologyName:  'MSAA'
 ClassName:  'WindowsForms10.BUTTON'
 ControlType:  'Window''r'n"}
代码:

WinWindow SearchButtonWindow = new WinWindow();
            SearchButtonWindow.SearchConfigurations.Add(SearchConfiguration.AlwaysSearch);
            SearchButtonWindow.SearchConfigurations.Add(SearchConfiguration.VisibleOnly);
            SearchButtonWindow.SearchProperties[WinWindow.PropertyNames.ControlType] = "Window";
            SearchButtonWindow.SearchProperties[WinWindow.PropertyNames.ControlName] = "cmdSearch";
            //SearchButtonWindow.WindowTitles.Contains("Ascend Retail Management Software");
            WinButton SearchButton = new WinButton();
            SearchButton.SearchConfigurations.Add(SearchConfiguration.AlwaysSearch);
            SearchButton.SearchConfigurations.Add(SearchConfiguration.VisibleOnly);
            SearchButton.SearchProperties[WinWindow.PropertyNames.ControlType] = "Button";
            SearchButton.SearchProperties[WinButton.PropertyNames.ControlName]= "cmdSearch";
            Mouse.Click(SearchButton);

编码ui:另一个控件正在阻塞该控件

从你的代码中我看到,SearchButtonWindow没有被分配为SearchButton的父。大多数情况下,还需要层次结构来唯一地标识控件。

WinButton = new WinButton(SearchButtonWindow);

另外,通过CodedUI Test Builder Tool检查SearchButtonWindow的子控件(一旦Window被高亮显示,使用Builder窗口右上角的箭头键)。向下箭头键指向当前突出显示的控件的直接第一个子控件,而右箭头键移动到兄弟控件)

尝试使用drawighlight()方法,查看test是否突出显示了正确的控件

我过去遇到过几次这种情况。通常当你想要的对象上面有一个不可点击的透明或其他不可见的对象时。您可以通过将鼠标强制移到对象位置,然后调用click命令来访问该对象。

Point? xyPoint = GetCenterPoint(SearchButton);
if (xyPoint != null)
{
   Mouse.Click((Point)xyPoint);
}

public Point? GetCenterPoint(UITestControl objTarget)
{
    Point? _Point = null;
    try
    {
        if (objTarget != null && objTarget.GetProperty(UITestControl.PropertyNames.BoundingRectangle) != null)
        {
            double _CenterX = objTarget.BoundingRectangle.X + (objTarget.BoundingRectangle.Width / 2);
            int _PointX = Convert.ToInt32(_CenterX);
            double _CenterY = objTarget.BoundingRectangle.Y + (objTarget.BoundingRectangle.Height / 2);
            int _PointY = Convert.ToInt32(_CenterY);
            _Point = new Point(_PointX, _PointY);
        }
    }
    catch (Exception ex)
    {
        //Exception Logging Here
    }
    return _Point;
}

您可以定义对象的位置,然后将鼠标放在其上并单击。

var clickTargetPoint = new System.Drawing.Point(*OBJECTNAME*.Left + *OBJECTNAME*.Width / 2, *OBJECTNAME*.Top + *OBJECTNAME*.Height / 2);
            Mouse.Hover(clickTargetPoint);
            Mouse.Click();