无法使用TestStack white选择Combobox选项

时间:2018-06-24 01:42:55

标签: teststack

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

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

1 个答案:

答案 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) { }
  }
}