1

如何从弹出的日历中选择日期?有一个文本字段处于禁用模式。当您单击文本字段角落的日历图标时,会弹出显示当前日期的日历。我需要选择两年前的日期。我该如何在 selenium java 中做到这一点?

下面是html代码:

<div class="datepicker datepicker-dropdown dropdown-menu" style="display: block; top: 429.1px; left: 234.5px;">
<div class="datepicker-days" style="display: block;">
 <table class=" table-condensed">
  <thead>
   <tr>
    <th class="prev" style="visibility: visible;">
    <i class="icon-arrow-left"></i>
    </th>
    <th class="switch" colspan="5">February 2009</th>
    <th class="next" style="visibility: visible;">
    <i class="icon-arrow-right"></i>
    </th>
   </tr>
   <tr>
    <th class="dow">Su</th>
    <th class="dow">Mo</th>
    <th class="dow">Tu</th>
    <th class="dow">We</th>
    <th class="dow">Th</th>
    <th class="dow">Fr</th>
    <th class="dow">Sa</th>
   </tr>
  </thead>
  <tbody>
   <tr>
   <tr>
   <tr>
   <tr>
   <tr>
   <tr>
  </tbody>
  <tfoot>
 </table>
</div>
<div class="datepicker-months" style="display: none;">
 <table class="table-condensed">
  <thead>
  <tbody>
   <tr>
    <td colspan="7">
     <span class="month">Jan</span>
     <span class="month">Feb</span>
     <span class="month">Mar</span>
     <span class="month">Apr</span>
     <span class="month">May</span>
     <span class="month">Jun</span>
     <span class="month">Jul</span>
     <span class="month">Aug</span>
     <span class="month">Sep</span>
     <span class="month">Oct</span>
     <span class="month">Nov</span>
     <span class="month">Dec</span>
    </td>
   </tr>
  </tbody>
  <tfoot>
 </table>
</div>
<div class="datepicker-years" style="display: none;">
</div> 
4

1 回答 1

0

使用 try catch 语句

在尝试中,您可以搜索页面中存在的元素(与要选择的日期相关的任何唯一元素)

在 catch 块中,您可以单击后退按钮。所以在这种情况下,它将继续单击日历中的后退/上一个按钮以转到前一年。

于 2013-07-30T06:53:05.533 回答