Set null value for ComboBox

Nov 2, 2010 at 1:49 AM
Edited Nov 2, 2010 at 4:40 AM

I am using a combobox to get data from database use datasource property. 

On creating new the combobox have an selectedIndex = -1, after saving the combobox have an selectedIndex <> -1

On editing i want to set the selectedIndex = -1. But i cant do it because the ArgumentOutOfRangeException was thrown.

Can someone help me out?

Nov 2, 2010 at 8:44 AM

Are there anybody give me some solutions pls?

Nov 2, 2010 at 8:59 AM

Hi

I think other forums will be faster generating an answer to this question.

For example

I don't have any experience in implementing UI.

 

Throndorin

Nov 2, 2010 at 9:27 AM

Hi! May be you miss understand my question!

I have a test case to test my content of validate message when i leave my combobox is blank using white!

Can u help me out?

Nov 2, 2010 at 9:44 AM

Ah ok

can you post the code you tried to test this scenario?

 

Throndorin

 

Nov 2, 2010 at 2:38 PM
Edited Nov 2, 2010 at 4:36 PM

This is my code:

var automationElement = main.GetElement(SearchCriteria.ByText("window")); 

var window = new MyCustomWindow(automationElement, InitializeOption.NoCache, application.ApplicationSession.WindowSession(InitializeOption.NoCache));

Assert.IsNotNull(window);

var cboRoom = window.Get<ComboBox>("cboRoom");

cboRoom.Select(-1); // this command thrown an ArgumentOutOfRangeException�

var messageBox = window.MessageBox("ECM");

Assert.NotNull(messageBox, "Dont display an error message!");

var label = messageBox.Get<Label>(SearchCriteria.All);

Assert.AreEqual(label.Text.Trim(), "my message");

messageBox.Close();

I also tried this code:

var automationElement = main.GetElement(SearchCriteria.ByText("window"));

var window = new MyCustomWindow(automationElement, InitializeOption.NoCache, application.ApplicationSession.WindowSession(InitializeOption.NoCache));

Assert.IsNotNull(window);

var cboRoom = window.Get<ComboBox>("cboRoom");

cboRoom.EditableText= string.Empty; // the textbox in the combobox was assigned to empty

var messageBox = window.MessageBox("ECM"); // But this command thrown an object NullRefenceException

Assert.NotNull(messageBox, "Dont display an error message!");

var label = messageBox.Get<Label>(SearchCriteria.All);

Assert.AreEqual(label.Text.Trim(), "my message");

messageBox.Close();

Another way i have used:

var cboRoom = window.Get<ComboBox>("cboRoom");
cboRoom.Click();
Keyboard.Instance.Enter(string.Empty);
But all of them are unsuccessfull.

 

 

 

Nov 2, 2010 at 3:10 PM

Hi

I think there isn't an element with index -1, all index for select are >0

there is an element in Combobox which has empty text right?

if you debug this which position does this element have in comboBox.Items?

This is the index you should choose.

 

Or if the items has Automation Id's use the longer way with

 

comboBox.Click();

ListItem item = comboBox.Items.Where(p=>p.AutomationElement.Current.AutomationID == "correct id").First();

item.Click();

Throndorin

 

 

Nov 3, 2010 at 7:29 AM
Edited Nov 3, 2010 at 7:32 AM

I have searched in UISpy but my combobox does not have any empty items (excep a list items, a textbox and a button).

In my application when i input empty to combobox the selectedIndex of the control will be reset to -1, so that nothing was selected (this is what i need)

But in my unit test code when i set EditableText = string.emtpy the combobox still only store the old item. Is it a bug of the white combobox?

I suggest white combobox need have an index will begin from -1 like the .NET combobox and when we input empty the index of the selected item need to be set to -1

Nov 3, 2010 at 7:42 AM

Hi

is there an empty list item visible for the user? can the user set this element?

than

 

open UISpy

open your application, go to the comboBox, click the comboBox (popup openes), press STRG and click with mouse on the emty element

 

what does UISpy show you?

 

Throndorin

Nov 3, 2010 at 7:44 AM

I checked UISpy but didn't have any empty item

Nov 3, 2010 at 7:58 AM

 

I believe this, but did you follow my instructions? And is it possible for the user to set an empty element?

Throndorin