This is a migrated thread and some comments may be shown as answers.

How to get an item count from a drop-down box

3 Answers 262 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 12 Apr 2011, 02:53 PM
How do I get the total count of items listed in a drop-down box.  For example, I have a smoke test that needs to verify that a drop-down box contains at least one item.  How can I use the built-in verification functionality to accomplish this?  Assistance appreciated in advance.

3 Answers, 1 is accepted

Sort by
0
Stoich
Telerik team
answered on 14 Apr 2011, 03:15 PM
Hi Jeff,
   the term drop-down encompasses a multitude of controls. What kind of a drop-down control is it? For a completely generic drop-down (i.e. an HTML Select) like this one:
http://www.w3schools.com/html/tryit.asp?filename=tryhtml_select2
you will need a coded step. I've attached a test that uses code to get the number of items for this drop-down and write them to the log. Depending on the particular dropdown used in your app the coded solution will look differently. Also, Test Studio might be able to build non-coded Verifications for some type of drop-down controls.

Hope to hear from you soon!

Kind regards,
Stoich
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jeff
Top achievements
Rank 1
answered on 30 Sep 2011, 08:55 PM
This is a jquery drop down

$(

 

'#CustomerId').size();

 



should get me the item count, no?  But how would I write a verification to ensure that there is at least one value?  I am not familiar with C#.
0
Stoich
Telerik team
answered on 04 Oct 2011, 09:06 AM
Hello Jeff,
   you'll need to go into the DOM structure of the application and examine how the items in the drop down are defined. Let's take the following application:
http://www.queness.com/resources/html/dropdownmenu/index.html#
We have 4 jquery drop-downs. When we bring up the DOM Explorer and we examine them we see that the items for each drop-down are defined in a UL (HTML Unordered List) (see screenshot 1). Now you can add the Unorder List item to the Elements Repository (screenshot 2).

Now you can access this element from a coded step:
Pages.SimpleDropDownMenu.UnorderedList
You're looking for the number of items in the menu. This corresponds to the number of LI elements inside of the UL. Since the LI elements are children of the UL you can use the following code to get their count:
Pages.SimpleDropDownMenu.UnorderedList.ChildNodes.Count
And you can write this value to the Log like this:
Log.WriteLine("Number of items in drop-down:"+Pages.SimpleDropDownMenu.UnorderedList.ChildNodes.Count.ToString());

I've attached the Test Project with the test demonstrating this example. I hope this helps.

Best wishes,
Stoich
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Jeff
Top achievements
Rank 1
Answers by
Stoich
Telerik team
Jeff
Top achievements
Rank 1
Share this question
or