How to click on a td class in selenium python

Question:

I’m using Selenium in Python and i’ve got some issues.
From a websites, there’s a calendar where users have to manually click on the date.

My issue is I’d like to click on a specific date with the Selenium code (.click()).
I haven’t found the way of selecting a date (for example the 27th) and allow Selenium to click on it.

Thanks for your help !

Below the following html code :

<div class="calendar" style="display: block; top: 515.667px; left: 50px;">
    <div class="month dual">
        <div class="wrapper">
            <header>
                <span class="prev arrow" style="display: none;">
                <span class="icons-arrow_black_left"></span>
                <span class="next arrow" style="display: none;"></span>
                <span class="icons-arrow_black_right"></span>
                <h1 data-automation-id="12">Décembre 2019</h1>
            </header>
            <table class="body" cellpadding="0" cellspacing="0" border="0">
                <tbody>
                    <tr>
                        <th>D</th>
                        <th>L</th>
                        <th>M</th>
                        <th>M</th>
                        <th>J</th>
                        <th>V</th>
                        <th>S</th>
                    </tr>
                    <div class="calendar" style="display: block; top: 515.667px; left: 50px;">
    <div class="month dual">
        <div class="wrapper">
            <header>
                <span class="prev arrow" style="display: none;">
                <span class="icons-arrow_black_left"></span>
                <span class="next arrow" style="display: none;"></span>
                <span class="icons-arrow_black_right"></span>
                <h1 data-automation-id="12">Décembre 2019</h1>
            </header>
            <table class="body" cellpadding="0" cellspacing="0" border="0">
                <tbody>
                    <tr>
                        <th>D</th>
                        <th>L</th>
                        <th>M</th>
                        <th>M</th>
                        <th>J</th>
                        <th>V</th>
                        <th>S</th>
                    </tr>
                    <tr>
                        <td class>1</td>
                        <td class>2</td>
                        <td class>3</td>
                        <td class>4</td>
                        <td class>5</td>
                        <td class>6</td>
                        <td class>7</td>
                    </tr>
                    <tr>
                        <td class>8</td>
                        <td class>9</td>
                        <td class>10</td>
                        <td class>11</td>
                        <td class>12</td>
                        <td class>13</td>
                        <td class>14</td>
                    </tr>
                    <tr>
                        <td class>15</td>
                        <td class>16</td>
                        <td class>17</td>
                        <td class>18</td>
                        <td class>19</td>
                        <td class>20</td>
                        <td class>21</td>
                    </tr>
                    <tr>
                        <td class>22</td>
                        <td class>23</td>
                        <td class>24</td>
                        <td class>25</td>
                        <td class>26</td>
                        <td class>27</td>
                        <td class>28</td>
                    </tr>
                    <tr>
                        <td class>29</td>
                        <td class>30</td>
                        <td class>31</td>

Asked By: Antoine F

||

Answers:

Can you try with:

xpath = '//table/tbody/tr[5]/td[6]'

for 27.th day in month

Answered By: josifoski

I think you should do something like this in XPATH:

//div[@class='calendar']//table//td[text()=27]

and no dictionaries needed

Answered By: Sergey Zakharov
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.