New*_*888 2 java selenium css-selectors selenium-webdriver drop-down-menu
我试图从下拉菜单中选择一个选项,直到单击定位器后才填充。这是我在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>
Run Code Online (Sandbox Code Playgroud)
到目前为止,我的代码是:
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);
}
Run Code Online (Sandbox Code Playgroud)
我得到一个UnexpectedTagNameException:元素应该是“ select”,但是是“ div”。我不确定如何处理此问题,因为我之前只使用过selects。
假设我要为代理代码选择“ 523-23-20275”。我将如何处理?
任何帮助表示赞赏!谢谢。
这不是正常的下拉选择菜单。因此,Select在这种情况下使用将不起作用。没有看到完整的网站,我不确定要选择哪个网站。
但是,div当下拉菜单中的选项可见时,请尝试简单地单击该元素。
//I'm assuming that this will display the dropdown list
driver.findElement(byAgentCodes).click();
driver.findElement(By.xpath("//div[@data-value='523-23-20275']"));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12527 次 |
| 最近记录: |