2016-08-31 73 views
0

我想使用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

有多少其他非常類似的問題在這裏堆棧溢出和其他網站你研究過嗎? – AdrianHHH

+0

我幾乎嘗試過。我沒有找到任何解決方案,他們都是解決方法,如獲取邊界,然後單擊,單擊使用KeyBoard輸入。但與我的應用程序的問題是,CodedUI顯示一個窗口和一個按鈕具有相同的控制名稱和相同的邊界。是否有任何方法,我們可以單擊按鈕使用Mouse.Click? –

回答

0

從你的代碼,我看到的是,SearchButtonWindow未被指定爲父搜索按鈕。大多數時間層次也是唯一識別控件所必需的。

WinButton SearchButton = new WinButton(SearchButtonWindow);

此外,通過CodedUI測試生成器工具檢查SearchButtonWindow的子控件(一旦窗口突出顯示,使用Builder窗口右上角的箭頭鍵,向下箭頭鍵將轉到當前突出顯示的控件的第一個子項,那裏的右箭頭鍵移動到兄弟姐妹)

0

嘗試使用Drawhighlight()方法,並發現測試是否突出了正確的控制

0

我遇到了在過去的這幾次。通常當你想要的對象頂部有一個不可點擊的透明對象或其他不可見對象時。您可以通過強制鼠標移動到對象位置,然後調用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; 
} 
相關問題