我无法点击量角器中的datepicker元素,如果该字段不可编辑,如何点击日期?
问题描述:
DatePicker字段是不可编辑的,我无法使用sendkeys发送数据。唯一的办法是点击日期。我尝试了很多选择,但没有任何工作。我无法点击量角器中的datepicker元素,如果该字段不可编辑,如何点击日期?
我想点击明天的日期,即今天+ 1日期。请参阅以下代码:
<input id="asOfDate" name="asOfDate" placeholder="Enter Date" readonly="true" ng-model="asOfDate" class="form-control date-picker asOfDate ng-pristine ng-valid ng-valid-pattern ng-touched" type="text" ng-pattern="/^([0]?\d{1}|[1][0-2])\/(([0-2]?\d{1})|([3][0,1]{1}))\/(([1]{1}[9]{1}[9]{1}\d{1})|([1-9]{1}\d{3}))$/" style="">
#addeventModal > div > div > div.modal-body.modal-body-height > form > div.row > div > div > span
<span ng-show="AddTimeLine.asOfDate.$error.pattern" class="text-danger ng-hide">Incorrect Format, should be MM/DD/YYYY</span>
<div class="datepicker-days" style="display: block;">
<table class=" table-condensed">
<thead>
<tr>
<th class="cw"> </th>
<th class="prev" style="visibility: visible;">
«</th>
<th colspan="5" class="datepicker-switch">October 2017</th>
<th class="next" style="visibility: visible;">»</th>
</tr>
<tr>
<th class="cw"> </th>
<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>
<td class="cw">39</td>
<td class="old day">24</td>
<td class="old day">25</td>
<td class="old day">26</td>
<td class="old day">27</td>
<td class="old day">28</td>
<td class="old day">29</td>
<td class="old day">30</td>
</tr>
<tr>
<td class="cw">40</td>
<td class="day">1</td>
<td class="day">2</td>
<td class="day">3</td>
<td class="day">4</td>
<td class="day">5</td>
<td class="day">6</td>
<td class="day">7</td>
</tr>
<tr>
<td class="cw">41</td>
<td class="day">8</td>
<td class="day">9</td>
<td class="day">10</td>
<td class="day">11</td>
<td class="day">12</td>
<td class="day">13</td>
<td class="day">14</td>
</tr>
<tr>
<td class="cw">42</td>
<td class="day">15</td><td class="day">16</td>
<td class="day">17</td><td class="day">18</td><td class="day">19</td>
<td class="day">20</td><td class="day">21</td></tr>
<tr><td class="cw">43</td><td class="day">22</td>
<td class="day">23</td><td class="day">24</td>
<td class="day">25</td><td class="day">26</td>
<td class="day">27</td><td class="day">28</td>
</tr><tr><td class="cw">44</td><td class="day">29</td>
<td class="day">30</td><td class="day">31</td>
<td class="new day">1</td>
<td class="new day">2</td>
<td class="new day">3</td>
<td class="new day">4</td>
</tr>
</tbody>
<tfoot>
<tr>
<th colspan="8" class="today" style="display: table-cell;">Today</th></tr><tr><th colspan="7" class="clear" style="display: none;">Clear</th></tr></tfoot></table></div>
如何为此编写代码?
答
增加一天以上问题
的帮助之后retrive一天
var day = todayTime.getDate();
既然你将有只有一个月显示,所有的日期将是独一无二的。 所以,你的XPath将
//td[@class="day"][text()=day]
你应该可以点击下面的代码
WebElement button = driver.findElement(By.xpath("//td[@class="day"][text()=day]
"));
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].click();", button);
我建议使用JavaScript的执行,因为有可能是一个叠加窗口
答
browser.executeScript("arguments[0].click();",element(by.xpath("[//td[@class="day"][text()=day]")).getWebElement());
PS:这里将当天传递为日变量。
我无法打开图片。请附上html代码。 –
不要在此处添加代码图片,而是在问题中添加代码 – Jeffin
已尝试此代码,尝试过评估选项,但这些都不起作用 var today = new Date(); var dd = today.getDate()+ 1; var mm = today.getMonth()+ 1; var yyyy = today.getFullYear(); –