Hi
I am having issues with UltraUiaComboBox. Simply i want to select item from dropdown and i do this:
Combobox.SelectedItem = "Item"... After this I see that it clicks on dropdown icon and it is moving from top to bottom of dropdown list and at the end if fails.
What is going on ?
i tried with http://msdn.microsoft.com/en-us/library/system.windows.automation.selectionitempattern.select.aspx
solution and it seams that everything is going to be ok but when it tries to do .select() ... Exception happens.
if this is not possible to do, is there any other way to get all items except combobox.items.
I made workaround to select dropdown item but this combobox.items method is taking long time to get all the items.
I am trying to get all items using NativeElements ..
Thanks to good friend Chris :) who pointed me in right direction i made workaround that looks like this:
UltraUiaComboBox uuComboBox = ( UltraUiaComboBox )control;
if ( uuComboBox.SelectedItem == providedValue) break;
AutomationElement containerAutomationElement = uuComboBox.NativeElement as AutomationElement; AutomationElementCollection elements = containerAutomationElement.FindAll( TreeScope.Children, Condition.TrueCondition ); uuComboBox.SetFocus(); Keyboard.SendKeys( "{HOME}" );
for ( int i = 0; i < elements.Count; i++ ) { try { string name = elements[ i ].Current.Name; if ( String.IsNullOrEmpty( name ) || name != providedValue) Keyboard.SendKeys( "{DOWN}" ); else break; } catch { } }
I know that this is not best solution but it is only one that works for me now. If someone finds other solution please reply on this thread.
Hello,
We are waiting for your feedback.
Hi All
It didn't work, but thanks, you did help me and now at least i have workaround that is working like a charm :)
Thanks a lot
Almir
Its very strange that the options we provided do not work for you. There must be something within the design of your application that we're not aware of. At least you have a workaround that meets your needs. Let us know if you have any other questions.
Chris.
Hi Chris
I am back with questions :)
Could you please help me with this?
I have UltraUiaCombobox with few items. I want to do assert on SelectedItem and when I try that it fails because for SelectedItem it actually selects Value property instead of Text.
And I am asserting by Text value (value that is visible to user).
Best
Hey Almir,
Try the following code:
public void AssertMethod1() { #region Variable Declarations UltraUiaComboBox uIUltraComboEditor1ComboBox = this.UIForm1Window.UIUltraComboEditor1Window.UIUltraComboEditor1ComboBox; #endregion
AutomationElement comboElement = uIUltraComboEditor1ComboBox.NativeElement as AutomationElement; if (comboElement == null) Assert.Fail("Could not locate the AutomationElement");
ItemContainerPattern containerPattern = comboElement.GetCurrentPattern(ItemContainerPattern.Pattern) as ItemContainerPattern; if (containerPattern == null) Assert.Fail("Could not locate the ItemContainerPattern on the AutomationElement");
AutomationElement selectedElement = containerPattern.FindItemByProperty(null, SelectionItemPatternIdentifiers.IsSelectedProperty, true); if (selectedElement == null) Assert.Fail("No Selected AutomationElement");
// change this line line to match your selected text
Assert.AreEqual("DisplayTextOfSelection", selectedElement.Current.Name); }
At this point, I'd be nervous about us changing the SelectedItem to be the display text of selected item, as it would most likely break existing tests that are expecting it to return the underlying value.
Chris
Works like a charm :D THANKS A LOT.
BestAlmir
Thanks Chris
I will try this code, and I will let you know is it working for me. For now I added some workaround that is working, but this code would be much more safe.