从div类下拉列表中选择-硒 [英] Selecting from div class dropdown - Selenium

查看:90
本文介绍了从div类下拉列表中选择-硒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从下拉菜单中选择一个选项,该选项在单击定位器之前不会填充.这是我在Firebug中看到的:

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>

到目前为止,我的代码是:

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);
    }

我得到一个 UnexpectedTagNameException:元素应该已经被选择",但是已经被"div" .我不确定如何处理此问题,因为我以前只使用过selects.

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.

假设我想为代理代码选择"523-23-20275".我将如何处理?

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

感谢您的帮助!谢谢.

推荐答案

这不是正常的下拉选择菜单.因此,在这种情况下,使用Select将不起作用.没有看到完整的网站,我不确定要选择哪个网站.

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.

但是,当下拉菜单中的选项可见时,只需尝试单击div元素.

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']"));

这篇关于从div类下拉列表中选择-硒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆