如何在 html 中的 zebra datepicker 中单击日期? [英] How to click on date in zebra datepicker in html?

查看:22
本文介绍了如何在 html 中的 zebra datepicker 中单击日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在听取了这里的人的建议后,我想我到达了某个地方.我又被卡住了.我必须使用 datepicker 从网站上抓取数据.html 表示该网站正在使用 Zebra 数据选择器.我必须点击日期,然后抓取数据.我正在努力点击日期.有人能帮我吗?

我必须点击 1/06/19.我无法想出一种方法来做到这一点.供参考:

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>

解决方案

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:

这篇关于如何在 html 中的 zebra datepicker 中单击日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆