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

4 posts, 0 answers
  1. Jeff
    Jeff avatar
    1 posts
    Member since:
    Oct 2012

    Posted 12 Apr 2011 Link to this post

    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.
  2. Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 14 Apr 2011 Link to this post

    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
  3. Jeff
    Jeff avatar
    1 posts
    Member since:
    Oct 2012

    Posted 30 Sep 2011 Link to this post

    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#.
  4. Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 04 Oct 2011 Link to this post

    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
Back to Top