-1

I have a calendar on my page, based on tr-td - tr is week, td - days.\

<table class="table">
  <tbody>
  <tr>...</tr>
  <tr>...</tr>
  <tr>
   <td class>
     <a href class="day">20</a>
    </td>
    ....
   <tr>...</tr>
   <tr>...</tr>
 </tbody>
</table>

I need to click on random day in this calendar. How can I correct do this? Thanks.

Devegnik
  • 195
  • 1
  • 3
  • 12

2 Answers2

2

As @https://stackoverflow.com/users/3472851/mehul-mohan radom number one from 1-30 if your days. Then use this

var random_day= 2;
var y = document.getElementsByClassName('day');
for(int i=0;i<y.lenght;i++){
   if(y[i].value ==random_day){
    click method on this ... 
    }
}

I am on phone so for actually code you need to wait a little bit. And give us more code because i don't know if you have more weeks and how their are defined.

Community
  • 1
  • 1
  • Hei, thanks for the answer. I just edit my question. In calendar there is one month. – Devegnik Mar 13 '17 at 13:39
  • Can you tell me what would click do or if click is all ready set up? I need more info I don't know is this some kinda of script for other page? I google nightwatch.js and it shows to me that is for scripting. Your code is not helping me a lot. Can you share more. – Lenart Poljanšek Mar 13 '17 at 17:14
0

You might need to go into the unpleasantness which is the browser.elements API to get all the .day elements and then do the click in the callback

Try this:

browser.elements('css selector', '.day', function (res) {
    var numDays = res.value.length;
    var randomDay = Math.floor(Math.random() * numDays);
    var selectedDay = res.value[randomDay];
    var jsonWebElementId = selectedDay.ELEMENT;
    browser.elementIdClick(jsonWebElementId);
});
derp
  • 2,300
  • 13
  • 20