1

使用以下代码选择组合框选项。单击组合框但未选择选项。

window.Get<ComboBox>(SearchCriteria.ByAutomationId("cbotire")).Select("Three");
4

1 回答 1

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) { }
  }
}
于 2019-04-26T12:29:32.340 回答