编码的 UI 测试集适当的问题
public HtmlComboBox NetworkSelectBox
{
get
{
HtmlComboBox networkSelectBox = new HtmlComboBox(ConfigVMPage);
networkSelectBox.SearchProperties[HtmlComboBox.PropertyNames.Id] = "vnic";
networkSelectBox.SearchProperties[HtmlComboBox.PropertyNames.Name] = "vnic";
networkSelectBox.FilterProperties[HtmlComboBox.PropertyNames.ControlDefinition] = "style=\"WIDTH: auto\" id=vnic name=vnic r";
return networkSelectBox;
}
}
上面是我定义一个 UI 元素并且我想设置属性的代码 NetworkSelectBox.SelectedItem = "LabNetworkSwitch";
我已经在其他元素上使用了这种方法并且全部成功,但是在这个元素中我收到了错误消息 Microsoft.VisualStudio.TestTools.UITest.Extension.ActionNotSupportedOnDisabledControlException:无法在禁用或只读控件上执行“SetProperty of SelectedItem with value“LabNetwokrSwitch””。
如何更改控件类型?
public HtmlComboBox NetworkSelectBox
{
get
{
HtmlComboBox networkSelectBox = new HtmlComboBox(ConfigVMPage);
networkSelectBox.SearchProperties[HtmlComboBox.PropertyNames.Id] = "vnic";
networkSelectBox.SearchProperties[HtmlComboBox.PropertyNames.Name] = "vnic";
networkSelectBox.FilterProperties[HtmlComboBox.PropertyNames.ControlDefinition] = "style=\"WIDTH: auto\" id=vnic name=vnic r";
return networkSelectBox;
}
}
Above is the code I define an UI element and I want to set the property
NetworkSelectBox.SelectedItem = "LabNetworkSwitch";
I've used this way on other elements and all success, but in this one i got the error message
Microsoft.VisualStudio.TestTools.UITest.Extension.ActionNotSupportedOnDisabledControlException: Cannot perform 'SetProperty of SelectedItem with value "LabNetwokrSwitch"' on the disabled or read-only control.
How can I change the control type?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您不想更改控件类型。我建议尝试 waitforready() 或 find()。可能发生的情况是,当控件最初被发现时它被禁用,find() 会将实际控件与当前的 networkSelectBox 同步。 WaitForReady() 可能是这里更好的方法,尽管它会隐式刷新组合框的值,直到可用于输入或超时已到。
我怀疑您会在使用 HtmlComboBoxes 时遇到此问题,但对于几个 WinComboBoxes,我遇到了无法使用 SelectedItem 或 SelectedIndex 设置它们的问题。我最终执行了 KeyBoardSendkeys(Combobox,"firstLetterOfItem") 直到所选值正确。
I don't think you want to change the control type. I would suggest trying either waitforready() or find(). What is likely happening is when the control is initially found it is disabled, and find() will sync the actual control with the current networkSelectBox. WaitForReady() is probably the preferable method here though it will implicitly refresh the values of the combo box until it is available for input or the time out has expired.
I doubt you will run into this issue with HtmlComboBoxes but with a couple of WinComboBoxes I have had issues where they could not be set using SelectedItem or SelectedIndex. I ended up doing KeyBoardSendkeys(Combobox,"firstLetterOfItem") until the selected value was correct.