简体   繁体   中英

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. 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".

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.

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:

http://selenium-python.readthedocs.org/en/latest/api.html

The Select() class is at section 7.12. UI Support

This should work

date = '30-Nov-2015'
driver.find_element_by_id("reportDate").send_keys(date)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM