1

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");
Shrini
  • 193
  • 10

1 Answers1

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) { }
  }
}
Jan Van Overbeke
  • 250
  • 3
  • 12