Select dropdown item for Bootstrap Multiselect dropdown

8 posts, 1 answers
  1. Chandresh
    Chandresh avatar
    41 posts
    Member since:
    May 2015

    Posted 27 Jul 2015 Link to this post

    Hi,
    In our application, we are using bootstrap multiselect dropdowns provided by GitHub. It generates html in ul/li format like below.

    <ul class="multiselect-container dropdown-menu">
            <li class="multiselect-item filter" value="0"><div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span><input class="multiselect-search" type="text" placeholder="Search"></div></li>
            <li class="multiselect-item multiselect-all"><a href="javascript:void(0);" class="multiselect-all"><label class="checkbox"><input type="checkbox" name="multiselect" value="multiselect-all"> Select All</label></a></li>
            <li><a href="javascript:void(0);"><label class="checkbox"><input type="checkbox" name="multiselect" value="Option 1"> Option 1</label></a></li>
            <li><a href="javascript:void(0);"><label class="checkbox"><input type="checkbox" name="multiselect" value="Option 2"> Option 2</label></a></li>
            <li><a href="javascript:void(0);"><label class="checkbox"><input type="checkbox" name="multiselect" value="Option 3"> Option 3</label></a></li>
            <li><a href="javascript:void(0);"><label class="checkbox"><input type="checkbox" name="multiselect" value="Option 12"> Option 12</label></a></li>
    </ul>

    Here I am trying to select "Option 3" using below code but it is not working. It performs click action but doesn't select value from dropdown. There are no change events bind for these dropdowns.

    IList<​HtmlListItem> List = Pages.TestPage.DropdownDiv.Find.AllByTagName<HtmlListItem>("li");
    foreach(HtmlListItem item in List)
    {
        if(item.InnerText.Contains("Option 3"));
        {
            Log.WriteLine("In!");
            item.​Click();
            break;
        }
    }

    Can anyone help me to resolve this ?

    Thanks,

    Chandresh

  2. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 28 Jul 2015 Link to this post

    Hello Chandresh,

    Instead of item.click please try item.MouseClick() instead.


    Regards,
    Cody
    Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
  3. Chandresh
    Chandresh avatar
    41 posts
    Member since:
    May 2015

    Posted 29 Jul 2015 Link to this post

    Hello Cody,

    I tried that but it didn't work.

    Thanks,

    Chandresh

  4. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 29 Jul 2015 Link to this post

    Hi Chandresh,

    I am sorry to hear that. The MouseClick was the only thing I could think of as an alternative. It makes me wonder if the mouse is moving and clicking on the right spot. If you watch the test run, can you see your mouse cursor move over the correct target element and Test Studio clicking on it? Or is the mouse moving to some unexpected location such as the top left corner of the browser? That's the only possible reason I can think of that MouseClick did not work as expected.

    Regards,
    Cody
    Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
  5. Chandresh
    Chandresh avatar
    41 posts
    Member since:
    May 2015

    Posted 06 Aug 2015 Link to this post

    Hi Cody,

    I am afraid I could not reply earlier ​but I was stuck with some priority work. However, I got this working using MouseClick. I did some digging yesterday and found that MouseClick was not working because I have more than 50 items in dropdown and the one which I want to click is not visible in the opened dropdown. I have to scroll through that and then I can click on it.

    What I did is that I have search box in the dropdown to search an item. So I searched for required item and then click on it. Here is the code which I used for it.

     

    HtmlInputText SearchTextbox = DropdownDiv.Find.ByAttributes<HtmlInputText>("class=multiselect-search");
    SearchTextbox.ScrollToVisible();
    SearchTextbox.Focus();
    SearchTextbox.MouseClick();
    ActiveBrowser.Manager.Desktop.KeyBoard.TypeText(SelectValue,50,100,true);
    System.Threading.Thread.Sleep(1000);
     
    IList<HtmlListItem> OptionLabels = DropdownDiv.Find.AllByTagName<HtmlListItem>("li");
    for(int i = 0; i < OptionLabels.Count;i++)
    {
        if(OptionLabels[i].InnerText.Equals("Option 2"))
        {
           OptionLabels[i].MouseClick(MouseClickType.LeftClick,0,0,ArtOfTest.Common.OffsetReference.AbsoluteCenter);
           break;
        }
    }
    System.Threading.Thread.Sleep(3000); 

     Thanks for your help Cody.

    Thanks,

    Chandresh

  6. Answer
    Cody
    Admin
    Cody avatar
    3360 posts

    Posted 07 Aug 2015 Link to this post

    Hi,

    Looks pretty good. I believe I can replace your loop with one line of code like this:
    HtmlInputText SearchTextbox = DropdownDiv.Find.ByAttributes<HtmlInputText>("class=multiselect-search");
    SearchTextbox.ScrollToVisible();
    SearchTextbox.Focus();
    SearchTextbox.MouseClick();
    ActiveBrowser.Manager.Desktop.KeyBoard.TypeText(SelectValue, 50, 100, true);
    System.Threading.Thread.Sleep(1000);
     
    //IList<HtmlListItem> OptionLabels = DropdownDiv.Find.AllByTagName<HtmlListItem>("li");
    //for (int i = 0; i < OptionLabels.Count; i++)
    //{
    //    if (OptionLabels[i].InnerText.Equals("Option 2"))
    //    {
    //        OptionLabels[i].MouseClick(MouseClickType.LeftClick, 0, 0, ArtOfTest.Common.OffsetReference.AbsoluteCenter);
    //        break;
    //    }
    //}
     
    DropdownDiv.Find.ByExpression<HtmlListItem>("TagName=li", "InnterText=" + SelectValue).MouseClick();
    System.Threading.Thread.Sleep(3000);


    Regards,
    Cody
    Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
  7. Chandresh
    Chandresh avatar
    41 posts
    Member since:
    May 2015

    Posted 12 Aug 2015 in reply to Cody Link to this post

    Thanks for your help Cody :) I will change that accordingly.

    Thanks,

    Chandresh

  8. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 12 Aug 2015 Link to this post

    Hello,

    Sounds good. I'll be here if you need further assistance with this.


    Regards,
    Cody
    Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
Back to Top