How to select more then 1 item in listbox using selenium c#?

Multi tool use
Multi tool use


How to select more then 1 item in listbox using selenium c#?


SelectElement Select = new SelectElement(driver.FindElement(By.Id("ddlCUcardNo")));
Select.SelectByIndex(2);



I have a problem with listbox using selenium C#. I need to select more then one item(option in the list). Is there any possilitiy to select two items (second with ctrl) ?



I would appreciate for any help please. As of now my code selects single item from the listbox.




2 Answers
2



If your listbox supports multiple select then the following code will select multiple values.


SelectElement Select = new SelectElement(driver.FindElement(By.Id("ddlCUcardNo")));
Select.SelectByIndex(2);
Select.SelectByIndex(3);
Select.SelectByIndex(4);



This will select the items indexed at 2, 3, 4 and make sure you have items more than 4.
You can check the listbox is multi select by the following code.


SelectElement Select = new SelectElement(driver.FindElement(By.Id("ddlCUcardNo")));
if(Select.IsMutiple)
console.log("list box is multi select");



All you need to do is to fire select commands on multiple elements one by one that’s it.


SelectElement element= new SelectElement(driver.FindElement(By.Id(element_ID)));
element.SelectByIndex(index);
element.SelectByIndex(index);

// Or can be used as
element.SelectByText(text);
element.SelectByText(text);

// Or can be used as
element.SelectByValue(value);
element.SelectByValue(value);






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Y LVPaoE7ZMxBQV,80u7hftFtfbwNv3d JY2sOJqh6,k,TqKlP9Hh 4 Mn5,7 UsdL2qhWUvaLSC3GHBRJtl
rSs5,smfLWmM

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications