Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 885
Surya sasidhar Avatar asked Sep 07 '16 12:09

Surya sasidhar


1 Answers

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..!!

like image 194
Rajesh S Avatar answered Sep 21 '22 19:09

Rajesh S