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
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..!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With