簡體   English   中英

選擇API在硒webdriver失敗?

[英]select api failing in selenium webdriver?

我正在嘗試從下拉列表中選擇日期值,但選擇api失敗

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

代碼片段是

<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>

您的“選擇”是輸入。 HTML選擇將是<select>

看起來有些JavaScript正在將您的輸入轉換為select。 如果您使用HtmlUnitDriver,請在其中啟用JavaScript或嘗試使用FirefoxDriver。

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

您可能還需要等一二秒才能執行JavaScript,然后再調用代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM