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

Select dropdown item for Bootstrap Multiselect dropdown

7 Answers 659 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Chandresh
Top achievements
Rank 1
Chandresh asked on 27 Jul 2015, 10:00 AM

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

7 Answers, 1 is accepted

Sort by
0
Cody
Telerik team
answered on 28 Jul 2015, 07:03 PM
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!
0
Chandresh
Top achievements
Rank 1
answered on 29 Jul 2015, 05:00 AM

Hello Cody,

I tried that but it didn't work.

Thanks,

Chandresh

0
Cody
Telerik team
answered on 29 Jul 2015, 08:45 PM
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!
0
Chandresh
Top achievements
Rank 1
answered on 06 Aug 2015, 05:19 AM

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

0
Accepted
Cody
Telerik team
answered on 07 Aug 2015, 04:22 PM
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!
0
Chandresh
Top achievements
Rank 1
answered on 12 Aug 2015, 08:42 AM

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

Thanks,

Chandresh

0
Cody
Telerik team
answered on 12 Aug 2015, 02:35 PM
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!
Tags
General Discussions
Asked by
Chandresh
Top achievements
Rank 1
Answers by
Cody
Telerik team
Chandresh
Top achievements
Rank 1
Share this question
or