1

I'm trying to do an automation with selenium so that, for example, today it selects today's date, tomorrow selects tomorrow's date, without having to keep changing it, as it is a task completion that must occur every day, I would like to know how to select the day according to the current day automatically in the calendar, follows the page's HTML code enter image description here

<table>
  <thead>
    <tr>
      <th>D</th>
      <th>S</th>
      <th>T</th>
      <th>Q</th>
      <th>Q</th>
      <th>S</th>
      <th>S</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td></td>
      <td><button type="button" class="v-btn v-btn--text v-btn--rounded theme--light"><div class="v-btn__content">1</div></button></td>
      <td><button type="button" class="v-btn v-btn--text v-btn--rounded theme--light"><div class="v-btn__content">2</div></button></td>
      <td><button type="button" class="v-btn v-btn--text v-btn--rounded theme--light"><div class="v-btn__content">3</div></button></td>
      <td><button type="button" class="v-btn v-btn--text v-btn--rounded theme--light"><div class="v-btn__content">4</div></button></td>
      <td><button type="button" class="v-btn v-btn--text v-btn--rounded theme--light"><div class="v-btn__content">5</div></button></td>
      <td><button type="button" class="v-btn v-btn--text v-btn--rounded theme--light"><div class="v-btn__content">6</div></button></td>
    </tr>
    <tr>
      <td><button type="button" class="v-btn v-btn--text v-btn--rounded theme--light"><div class="v-btn__content">7</div></button></td>
      <td><button type="button" class="v-btn v-btn--text v-btn--rounded theme--light"><div class="v-btn__content">8</div></button></td>
      <td><button type="button" class="v-btn v-btn--text v-btn--rounded theme--light"><div class="v-btn__content">9</div></button></td>
      <td><button type="button" class="v-btn v-btn--text v-btn--rounded theme--light"><div class="v-btn__content">10</div></button></td>
      <td><button type="button" class="v-btn v-btn--text v-btn--rounded theme--light"><div class="v-btn__content">11</div></button></td>
      <td><button type="button" class="v-btn v-btn--text v-btn--rounded theme--light"><div class="v-btn__content">12</div></button></td>
      <td><button type="button" class="v-btn v-btn--text v-btn--rounded theme--light"><div class="v-btn__content">13</div></button></td>
    </tr>
    <tr>
      <td><button type="button" class="v-btn v-btn--text v-btn--rounded theme--light"><div class="v-btn__content">14</div></button></td>
      <td><button type="button" class="v-btn v-btn--active v-btn--rounded theme--light accent"><div class="v-btn__content">15</div></button></td>
      <td><button type="button" class="v-btn v-date-picker-table__current v-btn--rounded v-btn--outlined theme--light accent--text"><div class="v-btn__content">16</div></button></td>
      <td><button type="button" class="v-btn v-btn--text v-btn--rounded theme--light"><div class="v-btn__content">17</div></button></td>
      <td><button type="button" class="v-btn v-btn--text v-btn--rounded theme--light"><div class="v-btn__content">18</div></button></td>
      <td><button type="button" class="v-btn v-btn--text v-btn--rounded theme--light"><div class="v-btn__content">19</div></button></td>
      <td><button type="button" class="v-btn v-btn--text v-btn--rounded theme--light"><div class="v-btn__content">20</div></button></td>
    </tr>
    <tr>
      <td><button type="button" class="v-btn v-btn--text v-btn--rounded theme--light"><div class="v-btn__content">21</div></button></td>
      <td><button type="button" class="v-btn v-btn--text v-btn--rounded theme--light"><div class="v-btn__content">22</div></button></td>
      <td><button type="button" class="v-btn v-btn--text v-btn--rounded theme--light"><div class="v-btn__content">23</div></button></td>
      <td><button type="button" class="v-btn v-btn--text v-btn--rounded theme--light"><div class="v-btn__content">24</div></button></td>
      <td><button type="button" class="v-btn v-btn--text v-btn--rounded theme--light"><div class="v-btn__content">25</div></button></td>
      <td><button type="button" class="v-btn v-btn--text v-btn--rounded theme--light"><div class="v-btn__content">26</div></button></td>
      <td><button type="button" class="v-btn v-btn--text v-btn--rounded theme--light"><div class="v-btn__content">27</div></button></td>
    </tr>
    <tr>
      <td><button type="button" class="v-btn v-btn--text v-btn--rounded theme--light"><div class="v-btn__content">28</div></button></td>
      <td><button type="button" class="v-btn v-btn--text v-btn--rounded theme--light"><div class="v-btn__content">29</div></button></td>
      <td><button type="button" class="v-btn v-btn--text v-btn--rounded theme--light"><div class="v-btn__content">30</div></button></td>
      <td><button type="button" class="v-btn v-btn--text v-btn--rounded theme--light"><div class="v-btn__content">31</div></button></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
  </tbody>
</table>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Stack Overflow policies discourage questions asking for general recommendations. You will need to try some options and do research online before coming back with specific and/or technical questions. – Michael Sohnen Aug 16 '22 at 22:48

1 Answers1

0

If you observe the HTML closely today's date i.e. 16 is highlighted as follows:

<td>
    <button type="button" class="v-btn v-date-picker-table__current v-btn--rounded v-btn--outlined theme--light accent--text">
        <div class="v-btn__content">16</div>
    </button>
</td>

Solution

To click on the highlighted day you can use either of the following locator strategies:

  • Using css_selector:

    driver.find_element(By.CSS_SELECTOR, "td > button.v-date-picker-table__current > div.v-btn__content").click()
    
  • Using xpath:

    driver.find_element(By.XPATH, "//td/button[contains(@class, 'v-date-picker-table__current')]/div[@class='v-btn__content']").click()
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • How did you get the CSS locator? I tried several ways to get it and I was just selecting the number, here's what was obtained when inspecting and copying the CSS: #app > div.v-menu__content.theme--light.menuable__content__active > div > div > div > div.v-date-picker-table.v-date-picker-table--date.theme--light > table > tbody > tr:nth-child(3) > td:nth-child(4) > button > div – Luiz Angelo Aug 17 '22 at 20:23
  • Let's discuss the issue in details within the Selenium Chat Room. – undetected Selenium Aug 17 '22 at 20:25
  • i don't have points enough – Luiz Angelo Aug 17 '22 at 20:44
  • Hmm, in short you have to validate the CSS within the Chrome Console, keep on uniquely identifying the desired node using CSS_SELECTOR. – undetected Selenium Aug 17 '22 at 20:47