简体   繁体   English

CODEDUI c#无法单击SharePoint功能区控件

[英]CODEDUI c# Cannot clickSharePoint Ribbon Control

As part of an automated test, I cannot click on the SharePoint Ribbon to select the "Alert Me" control. 作为自动化测试的一部分,我无法单击SharePoint功能区来选择“提醒我”控件。 I am getting the following error: 我收到以下错误:

Result Message: Test method CodedUITestProject2.CodedUITest1.SetAlert threw exception: Microsoft.VisualStudio.TestTools.UITest.Extension.FailedToPerformActionOnHiddenControlException: Cannot perform 'Click' on the hidden control. 结果消息:测试方法CodedUITestProject2.CodedUITest1.SetAlert引发了异常:Microsoft.VisualStudio.TestTools.UITest.Extension.FailedToPerformActionOnHiddenControlException:无法对隐藏的控件执行“单击”。 Additional Details: TechnologyName: 'Web' ControlType: 'Hyperlink' TagName: 'A' Id: 'Ribbon.Library.Share.AlertMe.Menu.Scope.AlertLibrary-Menu16' Name: '' Target: '' InnerText: 'Set alert on this library' ---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0xF004F002 其他详细信息:TechnologyName:'Web'控件类型:'Hyperlink'标记名:'A'ID:'Ribbon.Library.Share.AlertMe.Menu.Scope.AlertLibrary-Menu16'名称:”目标:” InnerText:'设置警报在此库上---> System.Runtime.InteropServices.COMException:来自HRESULT的异常:0xF004F002

Please find my code below: 1. and 2. work and it errors out at 3. I've tried adding and subtracting different control settings. 请在下面找到我的代码:1.和2.正​​常工作,并且在3处出错。我尝试添加和减去不同的控件设置。

//1. // 1。 Select the Library Tab on the ribbon 选择功能区上的“库”选项卡

        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);

This is a common thing happens with SharePoint automation. 这在SharePoint自动化中很常见。 Two reasons could be keeping you back from clicking on the "Alert Me" link. 有两个原因可能会阻止您单击“提醒我”链接。 1. Alert me is kept under a parent and you are trying to click directly. 1.提醒我,我被保留在父母的监护下,您尝试直接单击。 2. Two identical elements present where one is hidden and the other one is visible. 2.存在两个相同的元素,其中一个隐藏,而另一个可见。

I will give code for the second reason, if it doesn't works then you can try clicking by following the parent child hierarchy which is very easy to perform by your own. 我将给出第二个原因的代码,如果它不起作用,那么您可以尝试按照父子层次结构进行单击,这很容易由您自己执行。

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;
}
}

try above code. 尝试上面的代码。 Else follow the parent child relationship. 否则,遵循亲子关系。 Also it is not recommended to use UITestControl all the time to identify the elements please try to use specific class names say for example if you are trying to click on hyperlink instead of UITestControl use HtmlHyperlink class so that you can use all possible attributes to identify the elements. 另外,建议不要一直使用UITestControl来标识元素,请尝试使用特定的类名,例如,如果您要单击超链接而不是UITestControl,请使用HtmlHyperlink类,以便可以使用所有可能的属性来标识元素。元素。 This is a best practice which I follow. 这是我遵循的最佳做法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM