使用以下代码选择“组合框选项”。单击组合框,但未选择选项。
window.Get<ComboBox>(SearchCriteria.ByAutomationId("cbotire")).Select("Three");
答案 0 :(得分:0)
public static bool TrySelect(ComboBox combo, string val)
{
TryCollapse(combo.AutomationElement);
try
{
TryExpand(combo.AutomationElement);
Thread.Sleep(200);
combo.Select(val);
TryCollapse(combo.AutomationElement);
}
catch (Exception e) { }
if (combo.SelectedItemText == candidate)
{
TryCollapse(combo.AutomationElement);
return true;
}
TryCollapse(combo.AutomationElement);
return false;
}
public static void TryCollapse(AutomationElement ae)
{
object invoke;
if (ae.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out invoke))
{
try
{
(invoke as ExpandCollapsePattern).Collapse();
}
catch (Exception e) { }
}
}
public static void TryExpand(AutomationElement ae)
{
object invoke;
if (ae.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out invoke))
{
try
{
(invoke as ExpandCollapsePattern).Expand();
}
catch (Exception e) { }
}
}