How to select from drop-down list

8 posts, 0 answers
  1. Limu
    Limu avatar
    14 posts
    Member since:
    Oct 2010

    Posted 17 Nov 2010 Link to this post

    Hi,
    I want to select from a drop down list using webAii, C#.
    Initially the drop down is hidden. After clicking a radio button, drop down control becomes visible. It is set a default value. I need to select a differnt value from it.
    Below is the html
    <input type="hidden" name="firstnameId" value="" />
    <select class="name_selector" name="firstnameId" id="namesetselector">                               
       <option class="name_selector_option" value="1">Sam</option>
       <option class="name_selector_option" value="2">Mark</option>
       <option class="name_selector_option" value="3">Sean</option>
    </select>

    The code I have written is,
    HtmlSelect name = AB.Find.ByAttributes<HtmlSelect>("class=name_selector");
    name.SelectByValue("3");

    When I click the radio button and the drop down list becomes visible, by default the first option is selected. The above c# code that I have written actually selects the 3rd option in the drop-drown. Later on when I submit the page and open it, the option selected is the default one i.e. the first one. Is there a reason to this? When I do this operation manually it works fine.
    Thanks
  2. Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 19 Nov 2010 Link to this post

    Hi Limu,

       Would it be possible for you to provide us with the entire HTML page you're working with as well as the code of your test? I tried to reproduce the issue using the HTML and C# code you've provided but I couldn't.
     I implemented your HTML code, from the drop-down menu there I choose an option using your C# code: name.SelectByValue("3"); .
    However, upon submitting a GET Request to a mock server I get:

    Your input was received as:

    firstnameId=3

       which is what I expect. 

    The fact that I couldn't reproduce the issue makes me think it may be the result of more factors than just the local code of the drop-down menu and/or the C# code. 

    Of course we will fully understand if you are unable to provide us with any of the code you're working on. Please let us know

    Hope to hear from you soon!

    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. Limu
    Limu avatar
    14 posts
    Member since:
    Oct 2010

    Posted 19 Nov 2010 Link to this post

    Hi Stoich
    Sorry, I cant not provide the entire code or html. I simulated this in a web debugger, it seems that the value it is sending to the server is always the default one. The value of the drop-down is set programatically. So when I expand the drop-down and select a value, it is set properly and correct value is sent to the server. But the automation code is not expanding the drop-down list. It is just setting a value to the control and not really simulating the action.
    In web debugger I simulated this action with the below line
    $("#namesetselector").attr("selectedIndex", 2)

    Later when I view the request sent, it is sending the first option in the drop-down.

    Is there a way to make the automation tool perform this function correctly?
    Thanks
  4. Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 23 Nov 2010 Link to this post

    Hi Limu,
     
       We have an idea which might just work. You mention that if you extend the drop-down menu before selecting an element, you get the right result, correct? What we can do it use the WebUI Test Studio's Mouse Actions feature to trick the browser into expanding the drop-down menu as a separate step before selecting an option from the checkbox. What we do it simulates a click on the "expand" button which is part of the combobox. I decide it would be much easier to explain this visually so I've recorded a video which demonstrates what I mean and how it's done. Check it out:
    http://www.screencast.com/users/TelerikTesting/folders/Jing/media/0d3fb99e-63b3-4942-af64-d74db7acc170

    So in the same way you can expand your combobox before making the selection.

    Please let us know whether this solves your issue. Hope to hear from you soon! 

    Greetings,
    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
  5. Limu
    Limu avatar
    14 posts
    Member since:
    Oct 2010

    Posted 23 Nov 2010 Link to this post

    Hey Stoich
    I am not using the recorder but I am using the framework and manually coding in C#. So your solution wont help me. My code is given in the first message in this thread.
    Thanks
  6. Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 24 Nov 2010 Link to this post

    Hi Limu,

        you can still do it even though you don't WebUI Test Studio to generate the code for you. You just have to write it yourself.

    This is what my code for expanding this checkbox: http://w3schools.com/TAGS/tryit.asp?filename=tryhtml_option looks like:

    Select.MouseClick(ArtOfTest.WebAii.Core.MouseClickType.LeftClick, 35, -2, ArtOfTest.Common.OffsetReference.AbsoluteCenter);

    So you just have to call the same method on your HtmlSelect Object. 
    Just put this before the name.SelectByValue("3") like this:

    name.MouseClick(ArtOfTest.WebAii.Core.MouseClickType.LeftClick, 35, -2, ArtOfTest.Common.OffsetReference.AbsoluteCenter);

    One thing to keep in mind: the parameters "35, -2" are actually the coordinates where the click is supposed to occur relative to the center of the object. Your combobox probably has a different width/heigth than mine.
    This mean the X and Y coordinates (35,-2 for me) will also be different. You may have to play around with this a bit until you get it right and simulate a click on the expend button.

    Please let me know how this works out for you! 
     
    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
  7. Limu
    Limu avatar
    14 posts
    Member since:
    Oct 2010

    Posted 29 Nov 2010 Link to this post

    Hi Stoich,
    I tried the MouseClick code. It seems like the mouse touches the control but it dint seem to click it also the drop-down wont get expanded. May be the events with the drop-down control are not getting handled properly. Earlier I had similar experience with the radio button check() function. It appeared to be clicked but later the check value was not sent to the server. HtmlInputRadioButton.Check(true); method was not checking the radio button unless I explicitly said true in the second variable InvokeOnClickChanged as HtmlInputRadioButton.Check(true, true); I tried the same with the drop-down control but it did not seem to work.
    Thanks
  8. Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 01 Dec 2010 Link to this post

    Hi Limu,

    I am sorry to hear you continue to have problems getting this to work properly. Did you reuse my function without changing anything. What I mean is did you just copy-paste this :MouseClick(ArtOfTest.WebAii.Core.MouseClickType.LeftClick, 35, -2, ArtOfTest.Common.OffsetReference.AbsoluteCenter); 

    If so, this is probably the reason it doesn't work. Let me explain:

    In Select.MouseClick(ArtOfTest.WebAii.Core.MouseClickType.LeftClick, 35, -2, ArtOfTest.Common.OffsetReference.AbsoluteCenter); 35 and -2 are coordinates. They define where you want to click relative to the center of the Select element.

    In our case we want to click on the expand button of a combobox. So we have to know the correct coordinates. It easy with WebUI Test Studio because it lets you visually define the coordinates. However, you will have to calculate the coordinates yourself. One way to do it is to use a screenshot of the element. You can open this screenshot in Paint or a similar application which shows coordinates and calculate the coordinates of the expand button from there.

    Two things to keep in mind when you do this: keep the size (i.e. the pixel count) of the orignal screenshot otherwise you won't be able to make correct calculations. Also in Paint the coordinate system is such that (0,0) is the Upper-Left corner of an image. However, we use ArtOfTest.Common.OffsetReference.AbsoluteCenter i.e. the center of the image is (0,0). Check out screenshot 1 to see what I mean.

    If you have incorrect results for your expand button nothing will happen. You are able to compile and execute the function which tells us it's working. However, only clicking on the expand button of a combobox results in a visual action - if you click on any other part of the combobox nothing happens.
    Please make sure you have the correct coordinates for the click (this might involve some trial-and-error) and let me know whether it still won't work.

    Hope to hear from you soon!

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