Reputation: 13
Is there a method of going about selecting items from a checked list box in coded ui when the exact text contained within the list box item will not be known until runtime? Perhaps a method of selecting a list box item at a certain index?..
I've tried using click list box at point (x,y) but whenever a list item is in its place it throws and error because it is in the way, And i cant try clicking the list box item itself as the full text it displays is a randomly generated ID and i am not sure if there is another method of finding items.
Another possibility would be passing in the text of the list box item to select at run time?
This is currently what I am trying to do in order to grab the control although it's throwing errors due to type mismatch
Managed to get it working with the following:
WinList uIItemList = UIMainwindowWindow.UIClbxSearchResultsWindow.UIClbxSearchResultsList;
WinCheckBox listItem = (WinCheckBox)uIItemList.Items[0];
listItem.Checked = true;
Upvotes: 0
Views: 162
Reputation: 2890
Just set the SelectedIndex property of the list box after its been populated. The below very simple example sets it to item 3 ( Zero based index)
lstBox.SelectedIndex = 2;
As per your comments, the same can still be achieved on checked list box with the below.
chkListBox.SelectedIndex = 2;
chkListBox.SetItemCheckState(2, CheckState.Checked);
Hope that helps.
Upvotes: 2