简体   繁体   English

选择API在硒webdriver失败?

[英]select api failing in selenium webdriver?

Im trying to select the day value from a dropdown list.But the select api is failing 我正在尝试从下拉列表中选择日期值,但选择api失败

Select date=new Select(driver.findElement(By.id("dropdown_day")));
date.selectByIndex(5);

Code fragment is 代码片段是

<div id="dropdown_dropdown_day" class="dropdown" role="application" style="width: 32%;">
<input id="dropdown_day" type="hidden" value="0" name="dropdown_day">
<input id="btn_dropdown_day" class="btn-m btn-ter dropdown-toggle dropdown-input" type="text" style="min-height: 19px; width: 100%;" aria-haspopup="true" name="dp_dropdown_day" aria-owns="options_dropdown_day" aria-disabled="" role="combobox" readonly="readonly" title="" value="Day">
<i class="caret-dn-dp" aria-haspopup="true"></i>
<ul id="options_dropdown_day" class="dropdown-menu-dp" style="min-width: 60px; width: 100%;" aria-hidden="true" aria-activedescendant="" role="listbox">
<li class="op" aria-selected="true" tabindex="0" role="option" op-value="0">Day</li>
<li class="op" aria-selected="false" tabindex="-1" role="option" op-value="1">01</li>
<li class="op" aria-selected="false" tabindex="-1" role="option" op-value="2">02</li>
<li class="op" aria-selected="false" tabindex="-1" role="option" op-value="3">03</li>
<li class="op" aria-selected="false" tabindex="-1" role="option" op-value="3">...</li>
<li class="op" aria-selected="false" tabindex="-1" role="option" op-value="4">31</l
</ul>

Your 'select' is an input. 您的“选择”是输入。 Html select would be <select> . HTML选择将是<select>

Looks like some JavaScript is transforming your input into select. 看起来有些JavaScript正在将您的输入转换为select。 If you use HtmlUnitDriver please enable JavaScript in it or try to use FirefoxDriver. 如果您使用HtmlUnitDriver,请在其中启用JavaScript或尝试使用FirefoxDriver。

HtmlUnitDriver driver = new HtmlUnitDriver();
driver.setJavascriptEnabled(true);

You maybe also need to wait second or half for JavaScript to be executed before calling your code. 您可能还需要等一二秒才能执行JavaScript,然后再调用代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM