G.S. J
G.S. J

Reputation: 233

How to click on date in zebra datepicker in html?

After taking suggestions from people here, I think I reached somewhere. I again got stuck. I have to scrape data from a website using datepicker. html says that the website is using Zebra datapicker. I have to click on date and then scrape the data. I am struggling to click on date. Can someone help me?

I have to click on 1/06/19. I am not able to figure out a way to do this. For reference: http://apsdps.ap.gov.in/des_rainfall.html This is the website.

link = "http://apsdps.ap.gov.in/des_rainfall.html"
webdriver.Chrome(executable_path=r"chromedriver.exe")
driver = webdriver.Chrome() 
driver.get(link)
#driver.switch_to_frame(driver.find_element_by_xpath("//iframe"))
input_date = driver.find_element_by_name("date1")
input_date.click()

HTML:

<div class="Zebra_DatePicker" style="left: 222.375px; display: none; top: 0px;">
   <table class="dp_header" style="width: 218px;">
      <tbody>
         <tr>
            <td class="dp_previous">«</td>
            <td class="dp_caption">June, 2019</td>
            <td class="dp_next">»</td>
         </tr>
      </tbody>
   </table>
   <table class="dp_daypicker">
      <tbody>
         <tr>
            <th>Mo</th>
            <th>Tu</th>
            <th>We</th>
            <th>Th</th>
            <th>Fr</th>
            <th>Sa</th>
            <th>Su</th>
         </tr>
         <tr>
            <td class="dp_not_in_month">27</td>
            <td class="dp_not_in_month">28</td>
            <td class="dp_not_in_month">29</td>
            <td class="dp_not_in_month">30</td>
            <td class="dp_not_in_month">31</td>
            <td class="dp_weekend dp_selected">1</td>
            <td class="dp_weekend">2</td>
         </tr>
         <tr>
            <td>3</td>
            <td class="">4</td>
            <td>5</td>
            <td>6</td>
            <td>7</td>
            <td class="dp_weekend">8</td>
            <td class="dp_weekend">9</td>
         </tr>
         <tr>
            <td>10</td>
            <td>11</td>
            <td class="">12</td>
            <td>13</td>
            <td>14</td>
            <td class="dp_weekend">15</td>
            <td class="dp_weekend">16</td>
         </tr>
         <tr>
            <td>17</td>
            <td>18</td>
            <td class="">19</td>
            <td>20</td>
            <td>21</td>
            <td class="dp_weekend">22</td>
            <td class="dp_weekend">23</td>
         </tr>
         <tr>
            <td>24</td>
            <td>25</td>
            <td class="">26</td>
            <td>27</td>
            <td>28</td>
            <td class="dp_weekend">29</td>
            <td class="dp_weekend">30</td>
         </tr>
         <tr>
            <td class="dp_not_in_month">1</td>
            <td class="dp_not_in_month">2</td>
            <td class="dp_not_in_month">3</td>
            <td class="dp_not_in_month">4</td>
            <td class="dp_not_in_month">5</td>
            <td class="dp_not_in_month">6</td>
            <td class="dp_not_in_month">7</td>
         </tr>
      </tbody>
   </table>
   <table class="dp_monthpicker" style="width: 218px; height: 190px; display: none;"></table>
   <table class="dp_yearpicker" style="width: 218px; height: 190px; display: none;"></table>
   <table class="dp_footer" style="width: 218px;">
      <tbody>
         <tr>
            <td class="dp_today" style="width: 50%;">Today</td>
            <td class="dp_clear" style="width: 50%; display: table-cell;">Clear date</td>
         </tr>
      </tbody>
   </table>
</div>

Upvotes: 3

Views: 308

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193108

To send a date to the datepicker you can use the following Locator Strategies:

  • Code Block:

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument("start-maximized")
    driver = webdriver.Chrome(options=chrome_options)
    driver.get("http://apsdps.ap.gov.in/des_rainfall.html")
    driver.execute_script("arguments[0].removeAttribute('readonly')", WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "input#datepicker-example6"))))
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#datepicker-example6"))).send_keys("07/06/2019")
    
  • Browser Snapshot:

date

Upvotes: 1

Related Questions