ComboBox action results with exception

522 views Asked by At

I have this app that I need to write some automation for it. See image for data of that app. I'm using White / TestStack and C# and VS2015.

I'm trying to capture / get the combobox control (see image) and to set a value to it using the ComboBox.click() or Combobox.Select() methods. It looks like I can get the object but when I write in my code ComboBox.click() or Combobox.Select(1) it results with "system.invalidoperationexception" exception.

Note - if I write combobox.Click() in the "Watch" window of the VS2015 the action is performed, But if I write combobox.Select(1) I get an error.

below is my code for getting the combobox object.

public static bool ComboBoxByAutomationID(ref TestStack.White.UIItems.WindowItems.Window win, ref 
TestStack.White.UIItems.ListBoxItems.ComboBox comboBox, String AutoId)
    {
        for (int i = 0; i < nofRetries; i++)
        {
            if (win.Exists<TestStack.White.UIItems.ListBoxItems.ComboBox>(SearchCriteria.ByAutomationId(AutoId)))
            {
                comboBox = win.Get<TestStack.White.UIItems.ListBoxItems.ComboBox>(SearchCriteria.ByAutomationId(AutoId));
                mGenLog.Debug(System.Reflection.MethodBase.GetCurrentMethod().Name + ": Found " + AutoId + "[loop: " + i + "]");
                return true;
            }
            mGenLog.Debug(System.Reflection.MethodBase.GetCurrentMethod().Name + ": NOT Found " + AutoId + "[loop: " + i + "]");
        }
        mMainLog.Error(System.Reflection.MethodBase.GetCurrentMethod().Name + ": NOT Found " + AutoId + "[loop: " + nofRetries + "]");
        return false;
    }

So, just before the "return true" I added:

comboBox.Click();  
comboBox.Select(1);

And still I got an exception.

App Data:

App Data

Error:

System.InvalidOperationException was unhandled HResult=-2146233079 Message=Operation is not valid due to the current state of the object. Source=Interop.UIAutomationClient StackTrace: at UIAutomationClient.IUIAutomationElement.SetFocus() at System.Windows.Automation.AutomationElement.SetFocus() in d:\dev\UIAComWrapper\UiaComWrapper\AutomationElement.cs:line 455 at TestStack.White.UIItems.UIItem.Focus() in C:\projects\white-9yaco\src\TestStack.White\UIItems\UIItem.c‌​s:line 301 InnerException:

0

There are 0 answers