CODEDUI c#无法单击SharePoint Ribbon Control

时间:2016-07-28 22:20:43

标签: c# sharepoint automation coded-ui-tests ribbon-control

作为自动化测试的一部分,我无法单击SharePoint功能区以选择“Alert Me”控件。我收到以下错误:

结果讯息 测试方法CodedUITestProject2.CodedUITest1.SetAlert抛出异常: Microsoft.VisualStudio.TestTools.UITest.Extension.FailedToPerformActionOnHiddenControlException:无法对隐藏控件执行“单击”。额外细节: TechnologyName:'Web' ControlType:'超链接' TagName:'A' Id:'Ribbon.Library.Share.AlertMe.Menu.Scope.AlertLibrary-Menu16' 名称: '' 目标:'' InnerText:'在此库上设置警报'  ---> System.Runtime.InteropServices.COMException:来自HRESULT的异常:0xF004F002

请在下面找到我的代码:1。和2.工作,它在3处出错。我尝试添加和减去不同的控制设置。

// 1。选择功能区上的“库”选项卡

        UITestControl CLR = new UITestControl(browser);
        CLR.TechnologyName = "Web";
        CLR.SearchProperties.Add("InnerText", "LibraryLibrary Tools group. Tab 2 of 2.");
        CLR.WaitForControlReady();
        Mouse.Click(new Point(CLR.BoundingRectangle.X +   CLR.BoundingRectangle.Width / 2, CLR.BoundingRectangle.Y + CLR.BoundingRectangle.Height / 2));
        CLR.WaitForControlReady();
        //Mouse.Click(CLR);
        Playback.Wait(3000);

        //2. set focus on the a pane control on the ribbon    

        UITestControl FRL = new UITestControl(browser);
        FRL.TechnologyName = "Web";
        FRL.SearchProperties.Add("TagName", "SPAN");
        FRL.SearchProperties.Add("ControlType", "Pane");
        FRL.SearchProperties.Add("Class", "ms-cui-groupTitle");
        FRL.SearchProperties.Add("InnerText", "Share & Track");
        FRL.WaitForControlExist();
        FRL.SetFocus();
        Mouse.Click(new Point(FRL.BoundingRectangle.X + FRL.BoundingRectangle.Width / 2, FRL.BoundingRectangle.Y + FRL.BoundingRectangle.Height / 2));
        Playback.Wait(3000);


        //3. Click on "Alert Me" ID 
        UITestControl AM = new UITestControl(browser);
        AM.TechnologyName = "Web";            
        //AM.SearchProperties.Add("Inner Text", "Alert Me");
        AM.SearchProperties.Add("Id", "Ribbon.Library.Share.AlertMe-Large");
        AM.WaitForControlReady();
        Mouse.Click(new Point(AM.BoundingRectangle.X + AM.BoundingRectangle.Width / 2, AM.BoundingRectangle.Y + AM.BoundingRectangle.Height / 2));
        Playback.Wait(2000);

1 个答案:

答案 0 :(得分:0)

这是SharePoint自动化中常见的事情。 有两个原因可能会让您无法点击“提醒我”链接。 警告我是在父母的下面,你试图直接点击。 2.两个相同的元素存在,其中一个隐藏,另一个可见。

我将给出第二个原因的代码,如果它不起作用,那么你可以尝试点击父子层次结构,这很容易由你自己执行。

UITestControl AM = new UITestControl(browser);
//AM.TechnologyName = "Web";            
//AM.SearchProperties.Add("Inner Text", "Alert Me");
AM.SearchProperties.Add("Id", "Ribbon.Library.Share.AlertMe-Large");
AM.WaitForControlReady();
UITestControlCollection uic=AM.FindMatchingControls();
foreach(UITestControl ui in uic)
{
if(ui.BoundingRectangle.Width !=-1)
{
Mouse.Click(ui);
break;
}
}

尝试上面的代码。否则遵循父子关系。另外,建议不要一直使用UITestControl来识别元素,请尝试使用特定的类名称,例如,如果您尝试单击超链接而不是UITestControl,请使用HtmlHyperlink类,以便您可以使用所有可能的属性来识别元素。这是我遵循的最佳实践。