Selecting from div class dropdown - Selenium

24,765

This isn't a normal drop-down select menu. Hence, using Select won't work in this case. Without seeing the complete site, I'm not sure what exactly must be done to select it.

But try simply clicking on the div element when the options in the dropdown are visible.

//I'm assuming that this will display the dropdown list
driver.findElement(byAgentCodes).click(); 

driver.findElement(By.xpath("//div[@data-value='523-23-20275']"));
Share:
24,765
Admin
Author by

Admin

Updated on July 09, 2022

Comments

  • Admin
    Admin almost 2 years

    I'm trying to select an option from a drop-down that doesnt populate until the locator has been clicked. This is what I see in Firebug:

    div class="selectize-input items not-full has-options">
    <input type="text" autocomplete="off" tabindex="" placeholder="523-23-XXXXX" style="width: 109px; opacity: 1; position: relative; left: 0px;">
    </div>
    <div class="selectize-dropdown multi form-control" style="display: none; width: 263px; top: 34px; left: 0px; visibility: visible;">
    <div class="selectize-dropdown-content">
    <div class="option" data-selectable="" data-value="523-23-20273">523-23-20273</div>
    <div class="option" data-selectable="" data-value="523-23-20274">523-23-20274</div>
    <div class="option" data-selectable="" data-value="523-23-20275">523-23-20275</div>
    <div class="option" data-selectable="" data-value="523-23-20276">523-23-20276</div>
    <div class="option" data-selectable="" data-value="523-23-20280">523-23-20280</div>
    <div class="option" data-selectable="" data-value="523-23-202801">523-23-202801</div>
    

    The code I have so far is:

    public void selectAgentCodes(String agentCode)
        {
            driver.findElement(byAgentCodes).click();
            new WebDriverWait(driver, 5).until(ExpectedConditions.visibilityOfElementLocated(By.className("selectize-dropdown-content")));
            Select select = new Select(driver.findElement(By.className("selectize-dropwodn-content")));
            select.selectByVisibleText(agentCode);
        }
    

    I get an UnexpectedTagNameException: Element should have been "select" but was "div". I'm not sure how to handle this as I've only worked with selects before.

    Lets say I wanted to select "523-23-20275" for the agent code. How would I go about this?

    Any help is appreciated! Thanks.