1

Actually, I am able to select day and put the value.

Already try use some solution from other link :
1. Getting availability from datepicker
2. Python Selenium Date Picker
3. Python & Selenium Cannot select date in datepicker

When try to select month and year still no lock to get the result
Below my code :

start_date = wait.until(EC.visibility_of_element_located((
    By.CSS_SELECTOR, "#departureDate_i")))
start_date.click() #Show Datepciker
browser.execute_script("document.getElementsByClassName('next')[0].click()")
current_month = browser.find_element_by_css_selector(".datepicker-months").text
print("current_month:", current_month)

Below HTML format :

<div class="datepicker datepicker-dropdown dropdown-menu datepicker-orient-left datepicker-orient-top" style="display: none; top: 176.4px; left: 448.667px;">
   <div class="datepicker-days" style="display: block;">
      <table class=" table-condensed">
         <thead>
            <tr>
               <th class="prev" style="visibility: hidden;"></th>
               <th colspan="5" class="datepicker-switch">January 2019</th>
               <th class="next" style="visibility: visible;"></th>
            </tr>
            <tr>
               <th class="dow">Su</th>
               <th class="dow">Mo</th>
               <th class="dow">Tu</th>
               <th class="dow">We</th>
               <th class="dow">Th</th>
               <th class="dow">Fr</th>
               <th class="dow">Sa</th>
            </tr>
         </thead>
         <tbody>
            <tr>
               <td class="day disabled old">30</td>
               <td class="day disabled old">31</td>
               <td class="day disabled">1</td>
               <td class="day disabled">2</td>
               <td class="day">3</td>
               <td class="day today">4</td>
               <td class="day">5</td>
            </tr>
            <tr>
               <td class="day">6</td>
               <td class="day">7</td>
               <td class="day">8</td>
               <td class="day">9</td>
               <td class="day">10</td>
               <td class="day">11</td>
               <td class="day">12</td>
            </tr>
            <tr>
               <td class="day">13</td>
               <td class="day">14</td>
               <td class="day">15</td>
               <td class="day active">16</td>
               <td class="day">17</td>
               <td class="day">18</td>
               <td class="day">19</td>
            </tr>
            <tr>
               <td class="day">20</td>
               <td class="day">21</td>
               <td class="day">22</td>
               <td class="day">23</td>
               <td class="day">24</td>
               <td class="day">25</td>
               <td class="day">26</td>
            </tr>
            <tr>
               <td class="day">27</td>
               <td class="day">28</td>
               <td class="day">29</td>
               <td class="day">30</td>
               <td class="day">31</td>
               <td class="day new">1</td>
               <td class="day new">2</td>
            </tr>
            <tr>
               <td class="day new">3</td>
               <td class="day new">4</td>
               <td class="day new">5</td>
               <td class="day new">6</td>
               <td class="day new">7</td>
               <td class="day new">8</td>
               <td class="day new">9</td>
            </tr>
         </tbody>
         <tfoot>
            <tr>
               <th colspan="7" class="today" style="display: none;">Today</th>
            </tr>
            <tr>
               <th colspan="7" class="clear" style="display: none;">Clear</th>
            </tr>
         </tfoot>
      </table>
   </div>
   <div class="datepicker-months" style="display: none;">
      <table class="table-condensed">
         <thead>
            <tr>
               <th class="prev" style="visibility: hidden;"></th>
               <th colspan="5" class="datepicker-switch">2019</th>
               <th class="next" style="visibility: visible;"></th>
            </tr>
         </thead>
         <tbody>
            <tr>
               <td colspan="7" style=""><span class="month active">Jan</span><span class="month">Feb</span><span class="month">Mar</span><span class="month">Apr</span><span class="month">May</span><span class="month">Jun</span><span class="month">Jul</span><span class="month">Aug</span><span class="month">Sep</span><span class="month">Oct</span><span class="month">Nov</span><span class="month">Dec</span></td>
            </tr>
         </tbody>
         <tfoot>
            <tr>
               <th colspan="7" class="today" style="display: none;">Today</th>
            </tr>
            <tr>
               <th colspan="7" class="clear" style="display: none;">Clear</th>
            </tr>
         </tfoot>
      </table>
   </div>
   <div class="datepicker-years" style="display: none;">
      <table class="table-condensed">
         <thead>
            <tr>
               <th class="prev" style="visibility: hidden;"></th>
               <th colspan="5" class="datepicker-switch">2010-2019</th>
               <th class="next" style="visibility: visible;"></th>
            </tr>
         </thead>
         <tbody>
            <tr>
               <td colspan="7"><span class="year old disabled">2009</span><span class="year disabled">2010</span><span class="year disabled">2011</span><span class="year disabled">2012</span><span class="year disabled">2013</span><span class="year disabled">2014</span><span class="year disabled">2015</span><span class="year disabled">2016</span><span class="year disabled">2017</span><span class="year disabled">2018</span><span class="year active">2019</span><span class="year new">2020</span></td>
            </tr>
         </tbody>
         <tfoot>
            <tr>
               <th colspan="7" class="today" style="display: none;">Today</th>
            </tr>
            <tr>
               <th colspan="7" class="clear" style="display: none;">Clear</th>
            </tr>
         </tfoot>
      </table>
   </div>
</div>

much appreciate for suggest how to handle it
Thank you

  • 1
    Cool. Please provide an error or stack trace. Then we can help you. – Zhivko.Kostadinov Jan 04 '19 at 12:22
  • It's hard to help without knowing what error you're getting. If I were to speculate, I would guess you're currently getting all the text in the `datepicker-months` class. Looks like you'll want to narrow it down to the "month" `` that has the class `active`. But that's just a guess since I don't know what error you're getting. – Mike B Jan 05 '19 at 01:05
  • When use above code I get empty result. I try another way use this code : 'monthFromElements = element.find_element_by_xpath("//div[contains(@class, 'datepicker-months')]/table/tbody/tr/td") x = monthFromElements.find_elements_by_tag_name('span') for i in x: if i.get_attribute("innerText") == 'Apr': i.click()' This code return error :selenium.common.exceptions.ElementNotInteractableException: Message: Element could not be scrolled into view – Azda Firmansyah Jan 05 '19 at 07:57
  • Ah, the month and year elements in this snippet are set to `display: none`, so `element.text` will be empty (even if the element technically has text) and I doubt these elements will be clickable. So you'll have to use the site manually to find the triggers that make those elements visible, then replicate that in Selenium. Btw, the HTML snippet you've provided doesn't show anything because the outermost `div` is also set to `display:none`. – Mike B Jan 05 '19 at 20:45

0 Answers0