0
votes

As part of an automated test, I cannot click on the SharePoint Ribbon to select the "Alert Me" control. 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. 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

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

1 Answers

0
votes

This is a common thing happens with SharePoint automation. 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. 2. Two identical elements present where one is hidden and the other one is visible.

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. This is a best practice which I follow.