Failed To Perform Action On Blocked Control Exception? Using Coded UI?
Asked Answered
S

5

12

I am automating the WPF application, when i record "WpfComboBox" Control and performed select index on that control it is throwing error like "Failed To Perform Action On Blocked Control Exception". Please help me to over come this problem.

WpfControl customContr = new WpfControl(subDvnMap.SubDvsnItemCustom.SubDvsnItemTabList.SubDvsnPIPrismPrismExtensioTabPage);
customContr.SearchProperties.Add(WpfControl.PropertyNames.AutomationId, "legalFormatsControl");

WpfComboBox combLegal = new WpfComboBox(customContr);       
combLegal.SearchProperties.Add(WpfComboBox.PropertyNames.AutomationId, "legalFormats");
combLegal.Find();
combLegal.SelectedIndex = 2; 

the above is my code, it is throwing error at combLegal.selectedIndex =2

enter image description here

Supplicant answered 7/9, 2016 at 12:46 Comment(2)
when i write DrawHighlight() the blue line is visible, but unable to perform the selectSupplicant
What is "combLegal.Find()" supposed to do? can you remove it?Downtime
L
3

The Reason for this issue:

The control is placed inside an invisible control which is placed inside a parent control. As it is in your code, combLegal combobox is inside the customContr Wpfcontrol. but there is another control which blocks you accessing the combobox. The designers must have used this for some other purposes while debugging, and forgotten to remove it after they have done it.

The Possible solutions:


1. Try accessing the invisible control by its parent.

WpfControl customContr = new WpfControl(subDvnMap.SubDvsnItemCustom......);
customContr.SearchProperties.Add(....AutomationId, "legalFormatsControl");
foreach(WpfControl TempContr in customContr.GetChildren())
{
  WpfControl ChildContr = TempContr.GetChildren().ElementAt(0);
  if(ChildContr is WpfComboBox)
    {
     combLegal.SelectedIndex = 2;
     break;
    }
}



2. Try accessing control by checking its width.

WpfControl customContr = new WpfControl(subDvnMap.SubDvsnItemCustom......);
customContr.SearchProperties.Add(....AutomationId, "legalFormatsControl");
foreach(WpfControl TempContr in customContr.GetChildren())
{
   if(TempContr.BoundingRectangle.Width>0)
      {
        combLegal.SelectedIndex = 2;
        break;
      }
}



3. Try accessing control by checking its Parent's width.

  WpfControl customContr = new WpfControl(subDvnMap.SubDvsnItemCustom......);
    customContr.SearchProperties.Add(....AutomationId, "legalFormatsControl");
    foreach(WpfControl TempContr in customContr.GetChildren())
    {
       if(TempContr.BoundingRectangle.Width>0)
         {
           WpfControlCollection Collection = TempContr.GetChildren();
           foreach(WpfControl combLegal in Collection)
             {
               if(combLegal is WpfComboBox)
                 {
                  combLegal.SelectedIndex = 2;
                   break;
                 }
             }
         }
    }


One of these should resolve your issue. If not, do comment below, we shall give some more attempts. good luck..!!

Lickerish answered 14/9, 2016 at 11:53 Comment(1)
Hi Rajesh, no it is not working for me, i add my UI map. Please find the imageSupplicant
D
0

Hi I think you have performing some other operations on the same control earlier.

Better to add the same control again and rename it with some other name and make sure it is associated with this single action or operation only.

This will help you.

Dragonroot answered 20/9, 2016 at 12:25 Comment(3)
Thank you for reply Brahmanand, No i am not doing any operation on the control just i write control. SelectedIndex =2 still it is throwing the error.Supplicant
If you can try ,please try above solution once as i was facing the same issue earlier.Dragonroot
Yeah i did bhrahmanand, no it is not working. I am using 2013 Ultimate where it is not working, but it is working fine 2015Supplicant
U
0

This happens a lot in angular web-apps, where there's a parent control that's blocking the "real" one beneath it and also won't accept direct control. Ultimately @Rajesh-S is right on the money, and sometimes his parent-child approach is superior to this one. However it's not always the answer.

To get around it my team uses a method something like this. Use sparingly.

 /// <summary>
/// Clicks any control on a page for the given area.
/// </summary>
/// <param name="controlObject">Control Object to Click</param>
public static void ClickControl(UITestControl controlObject, int offset = 5)
{
    Rectangle clickArea = controlObject.BoundingRectangle;
    Point clickPoint = new Point(clickArea.X + offset, clickArea.Y + offset);
    Mouse.Click(clickPoint);
}

Pass in any control where you're getting the correct bounding box. Remember that the offset will be from the top left corner. Normally 5 is good to interact with most controls.

Unfavorable answered 26/9, 2016 at 18:21 Comment(0)
R
0
public static void ClickCenterOfAControl(UITestControl control)
{
    Point location = control.BoundingRectangle.Location;
    location.Offset(control.BoundingRectangle.Width / 2, control.BoundingRectangle.Height / 2);
    Mouse.Click(location);
}

Hope this will work

Rotary answered 7/10, 2016 at 13:57 Comment(0)
H
0

If the element is link or button then it works using the below line of code

Mouse.Click(element);

But, some times we might want to click on div tags or span tags instead of links. For that if the location where to click is not clear then also we get this type of error.

For this we can use the below line of code

Mouse.Click(element.BoundingRectangle.Location);
Hexastyle answered 4/4, 2017 at 9:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.