How to select today date & time(+15mins) from a date picker in selenium











up vote
1
down vote

favorite












I am unable to select todays date and time(plus 15 mins time) from the date picker in selenium.



Right now I have written the code for date which not working so here is the code-



 DateFormat dateFormat2 = new SimpleDateFormat("dd/MM/yyyy hh:mm a");
System.out.println("Format defined");
Date date2 = new Date();
System.out.println("Date object creation");
String today = dateFormat2.format(date2);
WebElement dateWidget = driver.findElement(By.xpath(".//*[@class='xdsoft_calendar']"));
System.out.println("Calendar web element");
List<WebElement> columns=dateWidget.findElements(By.tagName("div"));
System.out.println("listing web element");
System.out.println(today);
//comparing the text of cell with today's date and clicking it.
for (WebElement cell : columns)
{
System.out.println("In for loop"+cell.getText());
if (cell.getText().equals(today))
{
System.out.println("inside if");
System.out.println(today);
cell.click();
break;
}
}


Date picker
DatePicker



<div class="xdsoft_calendar">
<table>
<thead>
<tr>
<th>Sun</th>
<th>Mon</th>
<th>Tue</th>
<th>Wed</th>
<th>Thu</th>
<th>Fri</th>
<th>Sat</th>
</tr>
</thead>
<tbody>
<tr>
<td data-date="28" data-month="9" data-year="2018" class="xdsoft_date xdsoft_day_of_week0 xdsoft_date xdsoft_disabled xdsoft_other_month xdsoft_weekend">
<div>28</div>
</td>
<td data-date="29" data-month="9" data-year="2018" class="xdsoft_date xdsoft_day_of_week1 xdsoft_date xdsoft_disabled xdsoft_other_month">
<div>29</div>
</td>
<td data-date="30" data-month="9" data-year="2018" class="xdsoft_date xdsoft_day_of_week2 xdsoft_date xdsoft_disabled xdsoft_other_month">
<div>30</div>
</td>
</tr>
</tbody>
</table>
</div>


Note: 1.Expected is we should be able to select todays date
2. Current time +15 mins time from the date picker.



Its very tough i found guys, any help would be appreciated










share|improve this question




























    up vote
    1
    down vote

    favorite












    I am unable to select todays date and time(plus 15 mins time) from the date picker in selenium.



    Right now I have written the code for date which not working so here is the code-



     DateFormat dateFormat2 = new SimpleDateFormat("dd/MM/yyyy hh:mm a");
    System.out.println("Format defined");
    Date date2 = new Date();
    System.out.println("Date object creation");
    String today = dateFormat2.format(date2);
    WebElement dateWidget = driver.findElement(By.xpath(".//*[@class='xdsoft_calendar']"));
    System.out.println("Calendar web element");
    List<WebElement> columns=dateWidget.findElements(By.tagName("div"));
    System.out.println("listing web element");
    System.out.println(today);
    //comparing the text of cell with today's date and clicking it.
    for (WebElement cell : columns)
    {
    System.out.println("In for loop"+cell.getText());
    if (cell.getText().equals(today))
    {
    System.out.println("inside if");
    System.out.println(today);
    cell.click();
    break;
    }
    }


    Date picker
    DatePicker



    <div class="xdsoft_calendar">
    <table>
    <thead>
    <tr>
    <th>Sun</th>
    <th>Mon</th>
    <th>Tue</th>
    <th>Wed</th>
    <th>Thu</th>
    <th>Fri</th>
    <th>Sat</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <td data-date="28" data-month="9" data-year="2018" class="xdsoft_date xdsoft_day_of_week0 xdsoft_date xdsoft_disabled xdsoft_other_month xdsoft_weekend">
    <div>28</div>
    </td>
    <td data-date="29" data-month="9" data-year="2018" class="xdsoft_date xdsoft_day_of_week1 xdsoft_date xdsoft_disabled xdsoft_other_month">
    <div>29</div>
    </td>
    <td data-date="30" data-month="9" data-year="2018" class="xdsoft_date xdsoft_day_of_week2 xdsoft_date xdsoft_disabled xdsoft_other_month">
    <div>30</div>
    </td>
    </tr>
    </tbody>
    </table>
    </div>


    Note: 1.Expected is we should be able to select todays date
    2. Current time +15 mins time from the date picker.



    Its very tough i found guys, any help would be appreciated










    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I am unable to select todays date and time(plus 15 mins time) from the date picker in selenium.



      Right now I have written the code for date which not working so here is the code-



       DateFormat dateFormat2 = new SimpleDateFormat("dd/MM/yyyy hh:mm a");
      System.out.println("Format defined");
      Date date2 = new Date();
      System.out.println("Date object creation");
      String today = dateFormat2.format(date2);
      WebElement dateWidget = driver.findElement(By.xpath(".//*[@class='xdsoft_calendar']"));
      System.out.println("Calendar web element");
      List<WebElement> columns=dateWidget.findElements(By.tagName("div"));
      System.out.println("listing web element");
      System.out.println(today);
      //comparing the text of cell with today's date and clicking it.
      for (WebElement cell : columns)
      {
      System.out.println("In for loop"+cell.getText());
      if (cell.getText().equals(today))
      {
      System.out.println("inside if");
      System.out.println(today);
      cell.click();
      break;
      }
      }


      Date picker
      DatePicker



      <div class="xdsoft_calendar">
      <table>
      <thead>
      <tr>
      <th>Sun</th>
      <th>Mon</th>
      <th>Tue</th>
      <th>Wed</th>
      <th>Thu</th>
      <th>Fri</th>
      <th>Sat</th>
      </tr>
      </thead>
      <tbody>
      <tr>
      <td data-date="28" data-month="9" data-year="2018" class="xdsoft_date xdsoft_day_of_week0 xdsoft_date xdsoft_disabled xdsoft_other_month xdsoft_weekend">
      <div>28</div>
      </td>
      <td data-date="29" data-month="9" data-year="2018" class="xdsoft_date xdsoft_day_of_week1 xdsoft_date xdsoft_disabled xdsoft_other_month">
      <div>29</div>
      </td>
      <td data-date="30" data-month="9" data-year="2018" class="xdsoft_date xdsoft_day_of_week2 xdsoft_date xdsoft_disabled xdsoft_other_month">
      <div>30</div>
      </td>
      </tr>
      </tbody>
      </table>
      </div>


      Note: 1.Expected is we should be able to select todays date
      2. Current time +15 mins time from the date picker.



      Its very tough i found guys, any help would be appreciated










      share|improve this question















      I am unable to select todays date and time(plus 15 mins time) from the date picker in selenium.



      Right now I have written the code for date which not working so here is the code-



       DateFormat dateFormat2 = new SimpleDateFormat("dd/MM/yyyy hh:mm a");
      System.out.println("Format defined");
      Date date2 = new Date();
      System.out.println("Date object creation");
      String today = dateFormat2.format(date2);
      WebElement dateWidget = driver.findElement(By.xpath(".//*[@class='xdsoft_calendar']"));
      System.out.println("Calendar web element");
      List<WebElement> columns=dateWidget.findElements(By.tagName("div"));
      System.out.println("listing web element");
      System.out.println(today);
      //comparing the text of cell with today's date and clicking it.
      for (WebElement cell : columns)
      {
      System.out.println("In for loop"+cell.getText());
      if (cell.getText().equals(today))
      {
      System.out.println("inside if");
      System.out.println(today);
      cell.click();
      break;
      }
      }


      Date picker
      DatePicker



      <div class="xdsoft_calendar">
      <table>
      <thead>
      <tr>
      <th>Sun</th>
      <th>Mon</th>
      <th>Tue</th>
      <th>Wed</th>
      <th>Thu</th>
      <th>Fri</th>
      <th>Sat</th>
      </tr>
      </thead>
      <tbody>
      <tr>
      <td data-date="28" data-month="9" data-year="2018" class="xdsoft_date xdsoft_day_of_week0 xdsoft_date xdsoft_disabled xdsoft_other_month xdsoft_weekend">
      <div>28</div>
      </td>
      <td data-date="29" data-month="9" data-year="2018" class="xdsoft_date xdsoft_day_of_week1 xdsoft_date xdsoft_disabled xdsoft_other_month">
      <div>29</div>
      </td>
      <td data-date="30" data-month="9" data-year="2018" class="xdsoft_date xdsoft_day_of_week2 xdsoft_date xdsoft_disabled xdsoft_other_month">
      <div>30</div>
      </td>
      </tr>
      </tbody>
      </table>
      </div>


      Note: 1.Expected is we should be able to select todays date
      2. Current time +15 mins time from the date picker.



      Its very tough i found guys, any help would be appreciated







      javascript java selenium selenium-webdriver






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 9 at 11:35









      Navarasu

      1,8141721




      1,8141721










      asked Nov 8 at 19:17









      Sobhit Sharma

      35111




      35111
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          The question lacks some details, for instance how the html page of time selection looks, but anyway I will try to guess and help with what is possible to get from the qestion.



          As you are not able to select the current date most likely it happens because your condition is not met:



          if (cell.getText().equals(today))


          cell is a div and it's getText() should return 28, 29, and 30 respectively. And you compare it with the value dateFormat2.format(date2); which most likely return something like 08/11/2018 02:12 PM. Try the following modification (Java 8+):



          int currentDay = LocalDate.now().getDayOfMonth();
          if (cell.getText().equals(currentDay)) {

          }


          for hour and minutes logic either add how html looks like or just use LocalDate.now().getHour() to get current hour and implement similar condition to select necessary time. Hint: you might need to scroll to the necessary element.



          Take a closer look at LocalTime here






          share|improve this answer





















          • When I am getting blank value in cell.getText();
            – Sobhit Sharma
            Nov 9 at 15:35










          • @SobhitSharma could you please double check the HTML you posted in a question comparing to the one you actually have. If it is actual, then most likely the problem is that in the line WebElement dateWidget = driver.findElement(By.xpath(".//*[@class='xdsoft_calendar']")); you get ANOTHER calendar that is not currently shown. You can double check by changing .findElement to .findElements and check size. If there are multiple - make sure you select the correct one and try one more time.
            – Vladimir Efimov
            Nov 9 at 15:50










          • Yes you are right. Its my bad. The issue was in xpath due to which I was not able get the dates from the table and I was getting blank. Thanks again
            – Sobhit Sharma
            Nov 12 at 7:18


















          up vote
          0
          down vote














          1. Current time : Calendar cal= Calendar.getInstance();


          2. Add 15 Mins : cal.add(Calendar.MINUTE, 15);


          3. Return as date type : Date date = cal.getTime();







          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53214700%2fhow-to-select-today-date-time15mins-from-a-date-picker-in-selenium%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote



            accepted










            The question lacks some details, for instance how the html page of time selection looks, but anyway I will try to guess and help with what is possible to get from the qestion.



            As you are not able to select the current date most likely it happens because your condition is not met:



            if (cell.getText().equals(today))


            cell is a div and it's getText() should return 28, 29, and 30 respectively. And you compare it with the value dateFormat2.format(date2); which most likely return something like 08/11/2018 02:12 PM. Try the following modification (Java 8+):



            int currentDay = LocalDate.now().getDayOfMonth();
            if (cell.getText().equals(currentDay)) {

            }


            for hour and minutes logic either add how html looks like or just use LocalDate.now().getHour() to get current hour and implement similar condition to select necessary time. Hint: you might need to scroll to the necessary element.



            Take a closer look at LocalTime here






            share|improve this answer





















            • When I am getting blank value in cell.getText();
              – Sobhit Sharma
              Nov 9 at 15:35










            • @SobhitSharma could you please double check the HTML you posted in a question comparing to the one you actually have. If it is actual, then most likely the problem is that in the line WebElement dateWidget = driver.findElement(By.xpath(".//*[@class='xdsoft_calendar']")); you get ANOTHER calendar that is not currently shown. You can double check by changing .findElement to .findElements and check size. If there are multiple - make sure you select the correct one and try one more time.
              – Vladimir Efimov
              Nov 9 at 15:50










            • Yes you are right. Its my bad. The issue was in xpath due to which I was not able get the dates from the table and I was getting blank. Thanks again
              – Sobhit Sharma
              Nov 12 at 7:18















            up vote
            1
            down vote



            accepted










            The question lacks some details, for instance how the html page of time selection looks, but anyway I will try to guess and help with what is possible to get from the qestion.



            As you are not able to select the current date most likely it happens because your condition is not met:



            if (cell.getText().equals(today))


            cell is a div and it's getText() should return 28, 29, and 30 respectively. And you compare it with the value dateFormat2.format(date2); which most likely return something like 08/11/2018 02:12 PM. Try the following modification (Java 8+):



            int currentDay = LocalDate.now().getDayOfMonth();
            if (cell.getText().equals(currentDay)) {

            }


            for hour and minutes logic either add how html looks like or just use LocalDate.now().getHour() to get current hour and implement similar condition to select necessary time. Hint: you might need to scroll to the necessary element.



            Take a closer look at LocalTime here






            share|improve this answer





















            • When I am getting blank value in cell.getText();
              – Sobhit Sharma
              Nov 9 at 15:35










            • @SobhitSharma could you please double check the HTML you posted in a question comparing to the one you actually have. If it is actual, then most likely the problem is that in the line WebElement dateWidget = driver.findElement(By.xpath(".//*[@class='xdsoft_calendar']")); you get ANOTHER calendar that is not currently shown. You can double check by changing .findElement to .findElements and check size. If there are multiple - make sure you select the correct one and try one more time.
              – Vladimir Efimov
              Nov 9 at 15:50










            • Yes you are right. Its my bad. The issue was in xpath due to which I was not able get the dates from the table and I was getting blank. Thanks again
              – Sobhit Sharma
              Nov 12 at 7:18













            up vote
            1
            down vote



            accepted







            up vote
            1
            down vote



            accepted






            The question lacks some details, for instance how the html page of time selection looks, but anyway I will try to guess and help with what is possible to get from the qestion.



            As you are not able to select the current date most likely it happens because your condition is not met:



            if (cell.getText().equals(today))


            cell is a div and it's getText() should return 28, 29, and 30 respectively. And you compare it with the value dateFormat2.format(date2); which most likely return something like 08/11/2018 02:12 PM. Try the following modification (Java 8+):



            int currentDay = LocalDate.now().getDayOfMonth();
            if (cell.getText().equals(currentDay)) {

            }


            for hour and minutes logic either add how html looks like or just use LocalDate.now().getHour() to get current hour and implement similar condition to select necessary time. Hint: you might need to scroll to the necessary element.



            Take a closer look at LocalTime here






            share|improve this answer












            The question lacks some details, for instance how the html page of time selection looks, but anyway I will try to guess and help with what is possible to get from the qestion.



            As you are not able to select the current date most likely it happens because your condition is not met:



            if (cell.getText().equals(today))


            cell is a div and it's getText() should return 28, 29, and 30 respectively. And you compare it with the value dateFormat2.format(date2); which most likely return something like 08/11/2018 02:12 PM. Try the following modification (Java 8+):



            int currentDay = LocalDate.now().getDayOfMonth();
            if (cell.getText().equals(currentDay)) {

            }


            for hour and minutes logic either add how html looks like or just use LocalDate.now().getHour() to get current hour and implement similar condition to select necessary time. Hint: you might need to scroll to the necessary element.



            Take a closer look at LocalTime here







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 9 at 13:05









            Vladimir Efimov

            501211




            501211












            • When I am getting blank value in cell.getText();
              – Sobhit Sharma
              Nov 9 at 15:35










            • @SobhitSharma could you please double check the HTML you posted in a question comparing to the one you actually have. If it is actual, then most likely the problem is that in the line WebElement dateWidget = driver.findElement(By.xpath(".//*[@class='xdsoft_calendar']")); you get ANOTHER calendar that is not currently shown. You can double check by changing .findElement to .findElements and check size. If there are multiple - make sure you select the correct one and try one more time.
              – Vladimir Efimov
              Nov 9 at 15:50










            • Yes you are right. Its my bad. The issue was in xpath due to which I was not able get the dates from the table and I was getting blank. Thanks again
              – Sobhit Sharma
              Nov 12 at 7:18


















            • When I am getting blank value in cell.getText();
              – Sobhit Sharma
              Nov 9 at 15:35










            • @SobhitSharma could you please double check the HTML you posted in a question comparing to the one you actually have. If it is actual, then most likely the problem is that in the line WebElement dateWidget = driver.findElement(By.xpath(".//*[@class='xdsoft_calendar']")); you get ANOTHER calendar that is not currently shown. You can double check by changing .findElement to .findElements and check size. If there are multiple - make sure you select the correct one and try one more time.
              – Vladimir Efimov
              Nov 9 at 15:50










            • Yes you are right. Its my bad. The issue was in xpath due to which I was not able get the dates from the table and I was getting blank. Thanks again
              – Sobhit Sharma
              Nov 12 at 7:18
















            When I am getting blank value in cell.getText();
            – Sobhit Sharma
            Nov 9 at 15:35




            When I am getting blank value in cell.getText();
            – Sobhit Sharma
            Nov 9 at 15:35












            @SobhitSharma could you please double check the HTML you posted in a question comparing to the one you actually have. If it is actual, then most likely the problem is that in the line WebElement dateWidget = driver.findElement(By.xpath(".//*[@class='xdsoft_calendar']")); you get ANOTHER calendar that is not currently shown. You can double check by changing .findElement to .findElements and check size. If there are multiple - make sure you select the correct one and try one more time.
            – Vladimir Efimov
            Nov 9 at 15:50




            @SobhitSharma could you please double check the HTML you posted in a question comparing to the one you actually have. If it is actual, then most likely the problem is that in the line WebElement dateWidget = driver.findElement(By.xpath(".//*[@class='xdsoft_calendar']")); you get ANOTHER calendar that is not currently shown. You can double check by changing .findElement to .findElements and check size. If there are multiple - make sure you select the correct one and try one more time.
            – Vladimir Efimov
            Nov 9 at 15:50












            Yes you are right. Its my bad. The issue was in xpath due to which I was not able get the dates from the table and I was getting blank. Thanks again
            – Sobhit Sharma
            Nov 12 at 7:18




            Yes you are right. Its my bad. The issue was in xpath due to which I was not able get the dates from the table and I was getting blank. Thanks again
            – Sobhit Sharma
            Nov 12 at 7:18












            up vote
            0
            down vote














            1. Current time : Calendar cal= Calendar.getInstance();


            2. Add 15 Mins : cal.add(Calendar.MINUTE, 15);


            3. Return as date type : Date date = cal.getTime();







            share|improve this answer

























              up vote
              0
              down vote














              1. Current time : Calendar cal= Calendar.getInstance();


              2. Add 15 Mins : cal.add(Calendar.MINUTE, 15);


              3. Return as date type : Date date = cal.getTime();







              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote










                1. Current time : Calendar cal= Calendar.getInstance();


                2. Add 15 Mins : cal.add(Calendar.MINUTE, 15);


                3. Return as date type : Date date = cal.getTime();







                share|improve this answer













                1. Current time : Calendar cal= Calendar.getInstance();


                2. Add 15 Mins : cal.add(Calendar.MINUTE, 15);


                3. Return as date type : Date date = cal.getTime();








                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 9 at 13:19









                btshepo

                162




                162






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53214700%2fhow-to-select-today-date-time15mins-from-a-date-picker-in-selenium%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Schultheiß

                    Verwaltungsgliederung Dänemarks

                    Liste der Kulturdenkmale in Wilsdruff