Page 1 of 1

How to get Selected item list from a combo box dropdown list

Posted: Thu Apr 14, 2016 5:55 pm
by vivek.guvva
Hi,

I have a dropdown list when we can select multiple items. I need to unselect the already selected items and then select the items as need per my testcase. Could you please let me know how to unselect the already selected items. I have attached a snapshot of the dropdown list for reference.

Thanks
Vivek

Re: How to get Selected item list from a combo box dropdown list

Posted: Fri Apr 15, 2016 9:32 am
by odklizec
Hi,

I can only guess that the combo stays open until you close it and that you can select/deselect items by simple click on item (i.e. without the need to press and hold Ctrl or Shift)? In this case, you can use below method to find all "selected" items and click each of them them to deselect them.

To get the list of all selected items, you need to use xpath like this:

Code: Select all

/dom[@domain='mediaviewqc.nielsen.com']/body/div/div[#boundlist-1215-listWrap]/ul/li[@class~'-selected']
This xpath will return all selected items in your combo.

Now create a new repo element with such xpath. Then drag&drop it to recording module of your choice and from the appeared menu select UserCode >> New method with argument RepoItemInfo.

Then use this code, in newly created method, to create a list of selected elements and click each selected item to deselect it:

Code: Select all

	//create a list of LiTags using the "Info" object passed to method as repoiteminfo parameter
	IList<Ranorex.LiTag> liList =
		repoItemInfoElement.CreateAdapters<Ranorex.LiTag>();
	
	//click each found 'selected' combo item to deselect it
	foreach (Ranorex.LiTag liItem in liList)
	{
		liItem.Click();
	}
Where repoItemInfoElement points to the above mentioned repo element.

Re: How to get Selected item list from a combo box dropdown list

Posted: Tue Apr 19, 2016 11:33 am
by joshmike
hi vivek, put property "checked" in that element, it will automatically unselect when you select other option.