0

DatePicker field is non-editable and I cannot send data using sendkeys. The only way is to click on the date. I have tried many options but nothing is working.

I want to click on tomorrow's date that's today+1 date. Please see this code:

    <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">&nbsp;</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">&nbsp;</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>

How to write code for this?

halfer
  • 19,824
  • 17
  • 99
  • 186
  • 1
    I can't open the pictures. Please attach the html code also. – Sanja Paskova Oct 11 '17 at 08:55
  • Dont add pictures of code here , instead add the code in the question – Jeffin Oct 11 '17 at 08:58
  • have tried this code , tried evaluate option also but these are not working var today = new Date(); var dd = today.getDate() + 1; var mm = today.getMonth()+1; var yyyy = today.getFullYear(); – Sumathi Shekar Oct 11 '17 at 09:24
  • what you are asking is unclear. – Arunprasanth K V Oct 11 '17 at 09:49
  • sorry for the unclear picture of what am saying. I am trying to click on a date on a datepicker calendar . for this I have used above methods. but it's not working. Datepicker field is not typable, only way is to click on the date. i cannot send data using .sendKeys() . so please help me to click on date by reffering above code . – Sumathi Shekar Oct 11 '17 at 10:28

2 Answers2

0

Add days to JavaScript Date

Add a day with the help of above question

After that retrive the day

var day = todayTime.getDate();

Since you have will have only one month displayed, all dates will be unique. So your xpath would be

//td[@class="day"][text()=day]

You should be able to click with below code

WebElement button = driver.findElement(By.xpath("//td[@class="day"][text()=day]
"));
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].click();", button);

I suggest using javascript executor since there might be a overlay window

0
browser.executeScript("arguments[0].click();",element(by.xpath("[//td[@class="day"][text()=day]")).getWebElement());

Ps : here pass the current day as day variable.

Bhoomi Bhalani
  • 295
  • 5
  • 19