我正在使用Java从selenium中的日期选择器中选择日期。它不是文本框。我试过下面的代码,但它不起作用。有人可以帮忙吗?
driver.findElement(By.id("jobDate")).click();
WebElement dateWidget = driver.findElement(By.id("jobDate"));
List<WebElement> rows=dateWidget.findElements(By.tagName("tr"));
List<WebElement> columns=dateWidget.findElements(By.tagName("td"));
for (WebElement cell: columns){
//Select 28th Date
if (cell.getText().equals("28")){
cell.findElement(By.linkText("28")).click();
break;
}
}
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
以下是用于日期选择器的html代码。请看一看。
<div class="daterangepicker dropdown-menu ltr single opensright show-calendar" style="top: 652.75px; left: 674.5px; right: auto; display: block;">
<div class="calendar left single" style="display: block;">
<div class="daterangepicker_input">
<div class="calendar-table">
<table class="table-condensed">
<thead>
<tr>
<th></th>
<th class="month" colspan="5">
<select class="monthselect">
<option value="0" disabled="disabled">Januari</option>
<option value="1" disabled="disabled">Februari</option>
<option value="2" disabled="disabled">Maart</option>
<option value="3" disabled="disabled">April</option>
<option value="4" disabled="disabled">Mei</option>
<option value="5" selected="selected">Juni</option>
<option value="6">Juli</option>
<option value="7">Augustus</option>
<option value="8">September</option>
<option value="9">Oktober</option>
<option value="10">November</option>
<option value="11">December</option>
</select>
<select class="yearselect">
<option value="2017" selected="selected">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
<option value="2021">2021</option>
<option value="2022">2022</option>
</select>
</th>
<th class="next available">
<i class="fa fa-chevron-right glyphicon glyphicon-chevron-right"></i>
</th>
</tr>
<tr>
<th>ma.</th>
<th>di.</th>
<th>woe.</th>
<th>do.</th>
<th>vrij.</th>
<th>zat.</th>
<th>zo.</th>
</tr>
</thead>
<tbody>
<tr>
<td class="off off disabled" data-title="r0c0">29</td>
<td class="off off disabled" data-title="r0c1">30</td>
<td class="off off disabled" data-title="r0c2">31</td>
<td class="off disabled" data-title="r0c3">1</td>
<td class="off disabled" data-title="r0c4">2</td>
<td class="weekend off disabled" data-title="r0c5">3</td>
<td class="weekend off disabled" data-title="r0c6">4</td>
</tr>
<tr>
<td class="off disabled" data-title="r1c0">5</td>
<td class="off disabled" data-title="r1c1">6</td>
<td class="off disabled" data-title="r1c2">7</td>
<td class="off disabled" data-title="r1c3">8</td>
<td class="off disabled" data-title="r1c4">9</td>
<td class="weekend off disabled" data-title="r1c5">10</td>
<td class="weekend off disabled" data-title="r1c6">11</td>
</tr>
<tr>
<td class="off disabled" data-title="r2c0">12</td>
<td class="off disabled" data-title="r2c1">13</td>
<td class="off disabled" data-title="r2c2">14</td>
<td class="off disabled" data-title="r2c3">15</td>
<td class="off disabled" data-title="r2c4">16</td>
<td class="weekend off disabled" data-title="r2c5">17</td>
<td class="weekend off disabled" data-title="r2c6">18</td>
</tr>
<tr>
<td class="off disabled" data-title="r3c0">19</td>
<td class="off disabled" data-title="r3c1">20</td>
<td class="today active start-date active end-date in-range available" data-title="r3c2">21</td>
<td class="available" data-title="r3c3">22</td>
<td class="available" data-title="r3c4">23</td>
<td class="weekend available" data-title="r3c5">24</td>
<td class="weekend available" data-title="r3c6">25</td>
</tr>
<tr>
<td class="available" data-title="r4c0">26</td>
<td class="available" data-title="r4c1">27</td>
<td class="available" data-title="r4c2">28</td>
<td class="available" data-title="r4c3">29</td>
<td class="available" data-title="r4c4">30</td>
<td class="weekend off available" data-title="r4c5">1</td>
<td class="weekend off available" data-title="r4c6">2</td>
</tr>
<tr>
<td class="off available" data-title="r5c0">3</td>
<td class="off available" data-title="r5c1">4</td>
<td class="off available" data-title="r5c2">5</td>
<td class="off available" data-title="r5c3">6</td>
<td class="off available" data-title="r5c4">7</td>
<td class="weekend off available" data-title="r5c5">8</td>
<td class="weekend off available" data-title="r5c6">9</td>
</tr>
</tbody>
</table>
</div>
</div>
答案 0 :(得分:0)
要点击&#39; 28&#39;,请尝试以下代码 -
cell.findElement(By.xPath("//table[@class='table-condensed']//*[text()='28']")).click();
答案 1 :(得分:0)
通过以下代码
工作Promise