简体   繁体   English

如何使用Selenium和python为下拉日历赋予价值

[英]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.

相关问题 如何使用 Python 与 Selenium 一起 select 下拉菜单值? - How to select a drop-down menu value with Selenium using Python? 如何选择一个下拉菜单值与硒使用 python - how-to-select-a-drop-down-menu-value-with-selenium-using-python 如何使用Selenium / python根据Excel工作表中给出的值从下拉列表中选择一个值 - How to select a value from drop down based on the value given from Excel sheet using selenium/python 无法使用python中的Selenium从下拉列表中选择一个值 - Cant select a value from a drop down list using Selenium in python 单击并使用python 2 selenium选择javascript下拉菜单的值 - click and select value of javascript drop down menu using python 2 selenium 使用selenium python从下拉选项中选择一个值 - Selecting a value from a drop-down option using selenium python 如何使用 Selenium、Python 选择下拉菜单值 - How to select a drop-down menu value with Selenium, Python 如何在 python 中使用 selenium 下拉列表的 select 值 - How to select value of drop down list with selenium in python 如何从 python selenium 的下拉菜单中获取 select 的值 - How to select a value from drop down menu in python selenium 如何从具有特殊设置的网站上使用Selenium从下拉列表中选择一个值-Python - How to select a value from a drop-down using Selenium from a website with special setting- Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM