Python Selenium Firefox <input type =“ date” />使用.click()选择

时间:2018-08-17 20:59:56

标签: python-3.x selenium-webdriver

我知道其中有很多,但事实证明还没有帮助。无论我怎么努力,都找不到弹出式日历。有什么建议吗?

html:

<label for="id_start_date">Start Date</label>
  <input class="form-control" id="id_start_date" type="date" value="" />

测试文件:

    start_date = self.browser.find_element_by_id('id_start_date')

    start_date_label = self.browser.find_element_by_xpath(
        "//label[@for='id_start_date']"
    )
    self.assertEqual('Start Date', start_date_label.text)

    # Today's Date is preloaded into the field. Jeff clicks on it
    # and it pops open a little calender to choose a date.

    start_date.click()
    """
    What is supposed to go here so I can find and select my desired date?
    """

当我手动检查它时,它确实显示在我的页面上。我完全不知所措。

1 个答案:

答案 0 :(得分:0)

您不必单击日历。您可以设置值,因为它的类型为“输入”。 注意日期格式,假设下面的代码可以使用(MM / dd / yyyy)格式。

start_date = self.browser.find_element_by_id('id_start_date')
start_date.clear() # clear any value that was in the field before (if you don't clear, will append the new string sent.)
start_date.send_keys("08/17/2018")