Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Traverse Non-Select Dropdown using selenium?

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;
}
like image 986
Milo Avatar asked Dec 29 '25 20:12

Milo


1 Answers

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.

like image 177
JeffC Avatar answered Jan 01 '26 10:01

JeffC