WPFComboBox.Select doesn't work

Jun 4, 2008 at 10:27 AM
I'm using V0.14 and trying to use the Select method on a WPF combobox as follows in your WPFTestApplication

 

        WPFComboBox combo = WPFTestMainWindow.Get<WPFComboBox>(SearchCriteria.ByAutomationId("komboBox"));
        combo.Select(1);

 

The first line gets the combobox, the second line gives the exception I've included below.

Am I doing somethign wrong , should the above code snippet work?

Looking at the unit tests that are included in the core solution I can only see tests that check the .Seletc method on comboboxes against WinForms combo boxes, have you confirmed that the .Select actually works on a WPFComboBox?

Thanks,

James.


----
WPFTestApp.Test.ExercisingWhite.ComboBox:
Bricks.BricksException : Error invoking WPFComboBox.Select
  ----> System.InvalidOperationException : Unsupported Pattern.

at Bricks.RuntimeFramework.ReflectedObject.Invoke(MethodInfo methodInfo, Object[] arguments) in D:\bricks\Bricks.RuntimeFramework\ReflectedObject.cs:line 69
at Bricks.DynamicProxy.DynamicProxyInterceptors.Process(IInvocation invocation, Object interceptedObject) in D:\bricks\Bricks\DynamicProxy\DynamicProxyInterceptors.cs:line 20
at Core.Interceptors.CoreInterceptor.Intercept(IInvocation invocation) in c:\cruisecontrolrb\projects\white\work\Core\Interceptors\CoreInterceptor.cs:line 28
at Castle.DynamicProxy.AbstractInvocation.Proceed() in d:\OSS\Castle\Tools\Castle.DynamicProxy2\Castle.DynamicProxy\AbstractInvocation.cs:line 165
at WPFComboBoxProxy6a34a206247c4bdbb7fae0e683691d59.Select(Int32 index)
at WPFTestApp.Test.ExercisingWhite.ComboBox() in C:\QA\projects\NGDT\Tools\White\v014\WPFTestApp\Tests\Test.cs:line 320
--InvalidOperationException
at System.Windows.Automation.AutomationElement.GetCurrentPattern(AutomationPattern pattern)
at Core.UIItems.UIItem.Pattern(AutomationPattern pattern) in c:\cruisecontrolrb\projects\white\work\Core\UIItems\UIItem.cs:line 112
at Core.UIItems.ListBoxItems.WPFComboBox.VisiblityCheckPredicate() in c:\cruisecontrolrb\projects\white\work\Core\UIItems\ListBoxItems\WPFComboBox.cs:line 24
at Core.UIItems.ListBoxItems.ListControl.ActionPerforming(UIItem uiItem) in c:\cruisecontrolrb\projects\white\work\Core\UIItems\ListBoxItems\ListControl.cs:line 63
at Core.UIItems.ListBoxItems.ListItem.Select() in c:\cruisecontrolrb\projects\white\work\Core\UIItems\ListBoxItems\ListItem.cs:line 19
at Core.UIItems.ListBoxItems.ListItems.Select(Int32 index) in c:\cruisecontrolrb\projects\white\work\Core\UIItems\ListBoxItems\ListItems.cs:line 49
at Core.UIItems.ListBoxItems.ListControl.Select(Int32 index) in c:\cruisecontrolrb\projects\white\work\Core\UIItems\ListBoxItems\ListControl.cs:line 42
Jun 4, 2008 at 12:18 PM
The workaround I've found is:

    WPFComboBox combo = WPFTestMainWindow.Get<WPFComboBox>(SearchCriteria.ByAutomationId("komboBox")); 
    combo.Click();
    combo.Items[2].Click();

Thanks,

James

 

Jun 4, 2008 at 12:35 PM


jamesw wrote:
The workaround I've found is:

    WPFComboBox combo = WPFTestMainWindow.Get<WPFComboBox>(SearchCriteria.ByAutomationId("komboBox")); 
    combo.Click();
    combo.Items[2].Click();

Thanks,

James

 

 

Also the ComboBox control types in White dont provide methods to Expand and Collapse the combobox, would it possible for you to add this to White? (it can be achieved by implementing support for the ExpandCollapsePattern available on combobox controls).

Provinding support for the Expand/Collapse patterns would remove the need for the combo.Click(); in my above sample

Thanks,

James.
Coordinator
Jun 4, 2008 at 4:14 PM
Ideally you should be able to directly select an item and not do the detail tasks like you have to do now. That was the idea behind the select method.

I dont know whether you have upgraded to 0.15. This sounds like this issue (which was fixed):
http://www.codeplex.com/white/WorkItem/View.aspx?WorkItemId=1519

Do let me know if this works or not? In which case I would have to relook at the issue.
Jun 25, 2008 at 4:41 PM


viveksingh wrote:
Ideally you should be able to directly select an item and not do the detail tasks like you have to do now. That was the idea behind the select method.

I dont know whether you have upgraded to 0.15. This sounds like this issue (which was fixed):
http://www.codeplex.com/white/WorkItem/View.aspx?WorkItemId=1519

Do let me know if this works or not? In which case I would have to relook at the issue.



 Core.InputDevices.AttachedMouse mouse = window.Mouse;

 

System.Drawing.

Point point = new System.Drawing.Point(cbxBox.ClickablePoint.X + 40, cbxBox.ClickablePoint.Y);

 

mouse.Click(point);

cbxBox.Item(p).Select();

 

 

 

 

 

Jun 25, 2008 at 4:54 PM

Clicked 'Post your Message' too soon on that last one...

The Select() method on the WPFComboBox still throws an invalid operation exception (I'm on release 0.16)

The above workaround doesn't work in my situation but the one I've found that does is

 

 

Core.InputDevices.

AttachedMouse mouse = window.Mouse;

 

System.Drawing.

Point point = new System.Drawing.Point(cbxBox.ClickablePoint.X + 40, cbxBox.ClickablePoint.Y);

 

mouse.Click(point);

cbxBox.Item(p).Select();

 

 

 Hopefully this helps

Travis

Coordinator
Jun 25, 2008 at 8:01 PM
Someone else has raised a similar (InvalidOperationException) issue. If you send me the stacktrace then I verify that.
Thanks
Jun 26, 2008 at 7:17 PM


viveksingh wrote:
Someone else has raised a similar (InvalidOperationException) issue. If you send me the stacktrace then I verify that.
Thanks



This is the code I used to get the exception:

 


        Core.UIItems.ListBoxItems.WPFComboBox cbxBox = (Core.UIItems.ListBoxItems.WPFComboBox)pi.GetValue(this, null);
        
//cbxBox.Select(window.Mouse, p);
        
cbxBox.Select(p);

the variable p is a string that has the text of an item in the combobox

Stacktrace:
Initialization method ComponentTests.CustomerSearchTester.TestInit threw exception. Bricks.BricksException:  Bricks.BricksException: Error invoking WPFComboBox.Select --->  System.InvalidOperationException: Exception of type 'System.InvalidOperationException' was thrown..

System.Windows.Automation.AutomationElement.GetCurrentPattern(AutomationPattern pattern)
Core.UIItems.UIItem.Pattern(AutomationPattern pattern) in d:\white-os\Core\UIItems\UIItem.cs: line 115
Core.UIItems.ListBoxItems.WPFComboBox.get_VerticalSpan() in d:\white-os\Core\UIItems\ListBoxItems\WPFComboBox.cs: line 34
Core.UIItems.ListBoxItems.ListControl.ActionPerforming(UIItem uiItem) in d:\white-os\Core\UIItems\ListBoxItems\ListControl.cs: line 73
Core.UIItems.ListBoxItems.ListItem.get_Text() in d:\white-os\Core\UIItems\ListBoxItems\ListItem.cs: line 26
b__2(ListItem obj) in d:\white-os\Core\UIItems\ListBoxItems\ListItems.cs: line 33
Find(Predicate`1 match)
Core.UIItems.ListBoxItems.ListItems.Item(String text) in d:\white-os\Core\UIItems\ListBoxItems\ListItems.cs: line 33
Core.UIItems.ListBoxItems.ListControl.Item(String itemText) in d:\white-os\Core\UIItems\ListBoxItems\ListControl.cs: line 32
Core.UIItems.ListBoxItems.ListControl.Select(String itemText) in d:\white-os\Core\UIItems\ListBoxItems\ListControl.cs: line 43
Core.UIItems.ListBoxItems.ComboBox.Select(String itemText) in d:\white-os\Core\UIItems\ListBoxItems\ComboBox.cs: line 31
Bricks.RuntimeFramework.ReflectedObject.Invoke(MethodInfo methodInfo, Object[] arguments) in D:\bricks\Bricks.RuntimeFramework\ReflectedObject.cs: line 69
Bricks.DynamicProxy.DynamicProxyInterceptors.Process(IInvocation invocation, InterceptContext interceptedContext) in D:\bricks\Bricks\DynamicProxy\DynamicProxyInterceptors.cs: line 20
Core.Interceptors.CoreInterceptor.Intercept(IInvocation invocation) in d:\white-os\Core\Interceptors\CoreInterceptor.cs: line 29
Castle.DynamicProxy.AbstractInvocation.Proceed() in d:\OSS\Castle\Tools\Castle.DynamicProxy2\Castle.DynamicProxy\AbstractInvocation.cs: line 165
WPFComboBoxProxy4523eb250903477ab364a8a45df922e7.Select(String itemText)
SSCUIAutomation.Component.SetControlDefault(PropertyInfo pi, String p) in C:\QAonTFS\Development\SSCUIAutomation\SSCUIAutomation\Component.cs: line 63
SSCUIAutomation.Component.InitializeState() in C:\QAonTFS\Development\SSCUIAutomation\SSCUIAutomation\Component.cs: line 48
SSCUIAutomation.Component.Initialize() in C:\QAonTFS\Development\SSCUIAutomation\SSCUIAutomation\Component.cs: line 32
ComponentTests.ComponentTester.CheckReadiness() in C:\QAonTFS\Development\SSCUIAutomation\ComponentTests\ComponentTester.cs: line 41
ComponentTests.CustomerSearchTester.TestInit() in C:\QAonTFS\Development\SSCUIAutomation\ComponentTests\CustomerSearchTester.cs: line 22

Jun 26, 2008 at 7:27 PM

These are the workaround extension methods I've been using instead:

    public static void Click(this WPFComboBox cbxBox, AttachedMouse mouse) 
    {
        
int x = (int)cbxBox.Bounds.BottomRight.X - 10; 
        System.Drawing.
Point point = new System.Drawing.Point(x, cbxBox.ClickablePoint.Y); 
        mouse.Click(point);
    }

    public
static void Select(this WPFComboBox cbxBox, AttachedMouse mouse, int index) 
    {
        Click(cbxBox, mouse);
        cbxBox.Items[index].Click();
    }

    public
static void Select(this WPFComboBox cbxBox, AttachedMouse mouse, string itemString) 
    {
        Click(cbxBox, mouse);
        cbxBox.Item(itemString).Select();
    }
}

 

 

 

 

 

Nov 26, 2008 at 2:10 AM
I don't suppose this issue has been resolved yet or a work around is available that doesn't require the 3.5 framework.  I am 'stuck' using 3.0 and I did try the other solutions listed here to no avail.

Thanks.

Jared
Oct 15, 2009 at 9:58 PM

Yuck!  This works.

            cmboBox.Focus();
            for (int i = 0; i < index; i++)
            {
                Keyboard.Instance.PressSpecialKey(KeyboardInput.SpecialKeys.DOWN);
            }
        }
private void WPFCheckBoxSelectHack(ComboBox cmboBox, int index)
{
    cmboBox.Focus();
    for (int i = 0; i < index; i++)
    {
        Keyboard.Instance.PressSpecialKey(KeyboardInput.SpecialKeys.DOWN);
     }
}

 

 

 

 

 

Oct 19, 2009 at 7:25 AM

Hi

I am also having problem with the Combobox.select() method. I have tried many possible ways to select an item, but everything seems to be inconsistent.

All the Combobox in my application are dynamically populated.

To select an item, I am expanding the combo using ExpandCollapse pattern, Get all the items as textblocks and the click in the required textblock.

If I use snoop, I can see that the Listitems are displayed in a separate window when the combobox is expanded.

If I use UISPy, the list items are displayed in the same window or dialog. This confuses me...

 

Thanks

Logan

 

 

Coordinator
Nov 1, 2009 at 7:29 AM

@loganathan Can you provider some sample code to reproduce the problem

Jan 14, 2010 at 11:22 AM

Hi

ComboBox Select seems to have problems :(

I use Release 0.19

 

this works

ComboBox comboBoxSetupLanguageItem = (ComboBox)_dashboard.Get(SearchCriteria.ByAutomationId("comboBoxSetupLanguage"));
      
      // Get an entry from the combo box
      ListItem comboBoxEntry = comboBoxSetupLanguageItem.Items.Where(p => p.AutomationElement.Current.AutomationId == "comboBoxItemLanguageEnglish").First();//(ListItem)comboBoxSetupLanguageItem.Get(SearchCriteria.ByAutomationId("comboBoxItemLanguageEnglish"));
      AutomationElementHelper.SelectAutomationElement( comboBoxEntry.AutomationElement );

 

the SelectAutomationElement use the SelectionPattern :(

all other ways

comboBoxSetupLanguageItem.Select(Name);
comboBoxEntry.Select();

don't work, or don't work in all cases. Maybe there is a problem with lazy loading in comboboxes?

 


 

Jan 20, 2010 at 6:00 PM

I'm also having problems using the combobox select with a dynamically filled combobox. I am also trying

    public static void Select(this ComboBox cbxBox, AttachedMouse mouse, int index)
    {
      Click(cbxBox, mouse);
      cbxBox.Items[index].Click();
    }

    public static void Select(this ComboBox cbxBox, AttachedMouse mouse, string itemString)
    {
      Click(cbxBox, mouse);
      cbxBox.Item(itemString).Select();
    }

UnitTest_Functions.Select(CountryDDL, PersonSearchMouse, "United States");
but it isn't selecting anything. The only way I can (sort of) get it to work is passing keyboard commands to it.

        ComboBox CountryDDL = ArrestCreateWindow.Get<ComboBox>(SearchCriteria.ByAutomationId("PersonBirthInfo_BirthCountryCode"));
        Assert.IsNotNull(CountryDDL, "Place of Birth-Country DDL is not valid.");
        CountryDDL.Click();
        ArrestCreateWindow.Keyboard.Enter("u"); //presses the f key on the keyboard
        CountryDDL.KeyIn(KeyboardInput.SpecialKeys.RETURN);
        Thread.Sleep(150);

Do you know how I can get it to work through select instead of passing a key to it? Passing key commands is sometimes unreliable due to timing problems (that's why I put a thread.sleep in there), so it doesn't always work.

Jan 20, 2010 at 6:18 PM

Throndorin, do you have the code for that AutomationElementHelper?

Jan 26, 2010 at 12:04 AM

Ok, after testing and reproducing the code in White I found that the select function doesn't work for comboboxes (at least the ones I'm using) because the Item.Bounds value has an infinite x and y value. The real select function is supposed to click on the drop down list at a particular x and y of the item you're selecting, but somehow the code isn't getting back the right values. Not sure what's causing that.

Feb 2, 2012 at 12:53 PM

Hi,

I have the same problem with selecting from comboBox instead I used:

comboBox1.click();

subWindow.Keyboard.PressSpecialKey(KeyboardInput.SpecialKeys.UP);
subWindow.Keyboard.PressSpecialKey(KeyboardInput.SpecialKeys.RETURN);

is there any better way

Feb 6, 2012 at 12:55 PM

I'm having the same issues :-(

Feb 6, 2012 at 3:37 PM

Hi

 

comboBox.Click();  //opens the combobox so all items will be instanziated

Thread.Sleep(500);

ListItem item = combBob.Items.Where(p=>p.Name =="Name").First();  // get the needed Item from the menu

ComboBox.Click(); // click again to open the menu again

Thread.Sleep(500); wait the menu is open

item.Select(); select the item try also click();

 

in some cases you can use  a loop and verify the item is selected and try again if not.

this is a possible way

Feb 7, 2012 at 6:22 AM

this look fine but some times it doesn't work or require a (Thread.sleep()) statment before it.