gpt4 book ai didi

coded-ui-tests - 无法对阻塞的控制异常执行操作?使用编码的用户界面?

转载 作者:行者123 更新时间:2023-12-04 01:12:26 25 4
gpt4 key购买 nike

我正在自动化 WPF 应用程序,当我记录“WpfComboBox”控件并在该控件上执行选择索引时,它会抛出错误,例如“无法对阻止的控件异常执行操作”。请帮我解决这个问题。

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;

以上是我的代码,它在 combLegal.selectedIndex =2 处抛出错误

enter image description here

最佳答案

问题原因:该控件放置在一个不可见的控件中,该控件放置在父控件中。正如在您的代码中一样,combLegal组合框位于 customContr 内控制。但是还有另一个控件会阻止您访问组合框。设计人员一定是在调试时将其用于其他目的,并且在完成后忘记将其删除。 可能的解决方案:

1. 尝试通过其父级访问不可见控件。

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. 尝试通过检查其宽度来访问控制。
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. 尝试通过检查其父级的宽度来访问控制。
  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;
}
}
}
}

其中之一应该可以解决您的问题。如果没有,请在下面发表评论,我们将进行更多尝试。祝你好运..!!

关于coded-ui-tests - 无法对阻塞的控制异常执行操作?使用编码的用户界面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39370351/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com