Issue
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>
Solution
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()
Answered By - undetected Selenium
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.