我正在尝试使用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);
答案 0 :(得分:1)
尝试使用Drawhighlight()方法并查找测试是否突出显示正确的控件
答案 1 :(得分:1)
我过去曾经遇到过这种情况。通常当您想要的对象顶部有一个不可点击的透明或其他不可见对象时。您可以通过将鼠标强制到对象位置然后调用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;
}
答案 2 :(得分:0)
从您的代码中我看到,SearchButtonWindow未被指定为SearchButton的父级。大多数时间层次结构也是唯一标识控件所必需的。
WinButton SearchButton = new WinButton(SearchButtonWindow);
此外,通过CodedUI Test Builder工具检查SearchButtonWindow的子控件(一旦窗口突出显示,使用Builder窗口右上角的箭头键。向下箭头键转到当前突出显示的控件的第一个子项,右箭头键移动到兄弟姐妹的地方)
答案 3 :(得分:0)
有一种解决方法,您可以定义对象的位置,然后将鼠标放在其上并单击。
var clickTargetPoint = new System.Drawing.Point(*OBJECTNAME*.Left + *OBJECTNAME*.Width / 2, *OBJECTNAME*.Top + *OBJECTNAME*.Height / 2);
Mouse.Hover(clickTargetPoint);
Mouse.Click();
这对我有帮助。