[英]How to give value to a drop down calendar using selenium and python
I am new to selenium and i am building this code where i have to give a certain value to the drop down calendar, and i am totally confused. 我是硒的新手,我正在构建此代码,在其中我必须为下拉日历提供一定的值,而我对此感到非常困惑。
Below is the html code for the website calendar i am trying to use. 以下是我要使用的网站日历的html代码。 Do help. 帮忙
<input id="reportDate" name="criteria.reportDate" value="30-Nov-2015" class="form-control datepicker-control form-date" type="text">
This is the code i used so far 这是我到目前为止使用的代码
driver=webdriver.Chrome()
driver.get('url')
driver.find_element_by_id('reportData').click()
i am not sure as to how to proceed after this. 我不确定如何进行此操作。
i already wrote the code to get the date value in "30-Nov-2015" format which is in the variable "date". 我已经写了代码以获取变量“ date”中“ 30-Nov-2015”格式的日期值。
Sorry if the code is too small to work on, totally new to this. 很抱歉,如果代码太小而无法使用,这是全新的。
I am assuming you have to select the date from the dropdown calender, you can use Select class for that. 我假设您必须从下拉日历中选择日期,可以使用Select类。
driver=webdriver.Chrome()
driver.get('url')
select = Select(driver.find_element_by_id("reportData"))
select.select_by_visible_text("30-Nov-2015")
you can also use - 您还可以使用-
select.select_by_value("30-Nov-2015")
You can see the WebDriver API bindings in Python here: 您可以在以下位置查看Python中的WebDriver API绑定:
http://selenium-python.readthedocs.org/en/latest/api.html http://selenium-python.readthedocs.org/en/latest/api.html
The Select() class is at section 7.12. Select()类位于7.12节。 UI Support 用户界面支持
This should work 这应该工作
date = '30-Nov-2015'
driver.find_element_by_id("reportDate").send_keys(date)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.