在UI自动化中,当自动化工具条项目时,我们面临一个问题,如下所述
我正在添加工具条项目,如下所示
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripButton1, this.toolStripButton2, this.toolStripComboBox1, this.toolStripButton3});
当运行UI自动化(System.Windows.Automation)时,UI自动化将查找控件,直到toolstripcombobox左侧的toolStripButton2 (即)控件被识别出来,但控件位于右侧。(如果我将组合框设置为最右侧的控件,则一切正常)
注意:在windows工具包的Inspect.exe工具中,所有控件都会显示,但当尝试访问最后一个toolStripButton3时,会返回null。
这里我附上了简化的代码,buttonCollection应该有3个按钮,但在我的情况下它只有2个按钮。
AutomationElement toolstrip = viewTab.FindFirst(TreeScope.Children,
new PropertyCondition(AutomationElement.AutomationIdProperty, "toolStrip1"));
AutomationElementCollection buttonCollection = toolstrip.FindAll(TreeScope.Children,
new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "button"));ToolStripTextBox和ToolStripComboBox都显示出相同的行为。
我想知道我的方法出了什么问题。
发布于 2015-10-13 03:17:05
https://stackoverflow.com/questions/33012393
复制相似问题