I am trying to get all the options available in a KendoUI dropdown which uses 'k-dropdown' as its control rather than a 'select'. Therefore, I cannot use something like (since there is no select element):
public void ChooseOrderType(string type)
{
var mySelect = new SelectElement(TypeDropDownLocator);
var options = mySelect.Options;
foreach (var option in options) {
if (option.Text.Equals(type))
option.Click();
}
}
HTML:
<span class="k-widget k-dropdown k-header" unselectable="on" role="listbox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-owns="orderStatus_listbox" aria-disabled="false" aria-readonly="false" aria-busy="false" aria-activedescendant="orderStatus_option_selected">
<span unselectable="on" class="k-dropdown-wrap k-state-default">
<span unselectable="on" class="k-input">All orders</span>
<span unselectable="on" class="k-select">
<span unselectable="on" class="k-icon k-i-arrow-s">select</span>
</span>
</span>
<input id="orderStatus" name="orderStatus" type="text" data-role="dropdownlist" style="display: none;">
</span>
Is there any way to traverse this manually to get all the options?
EDIT: I got it working with JeffC's method:
public ViewOrdersPage SearchDraftOrders(string type)
{
TypeDropDownLocator.Click();
Driver.FindElement(By.XPath("id('orderStatus_listbox')/li[2]")).Click();
SearchOrdersButton.Click();
return this;
}
As you discovered, you won't be able to use the SelectElement type. You will need to instead treat it like any other element. You will need to click the SELECT-like element to open the dropdown and then click the element that represents the OPTION-like element you want selected. You may need a short wait between the two clicks, depending on the speed of the dropdown opening.
Without seeing the entirety of the HTML used for the dropdown and options, I can't provide code but you can likely figure it out on your own give the directions above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With