Unable to select Combobox option using TestStack white

727 Views Asked by At

Using the below code to select Combobox Option. Combo box is clicked but option is not selected.

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

There are 1 best solutions below

0
On
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) { }
  }
}