python - 如何在selenium python中的jquery日期时间选择器中选择日期

标签 python python-3.x selenium selenium-webdriver web-scraping

我想从 iframe 中存在的 jquery 日期时间选择器中选择日期和时间。我已切换到框架并单击打开日期时间选择器的字段,但我想从我的代码发送值(如发送键),但我无法发送。我正在 python 中执行此操作。

这是我的 html 代码:

<div class="add_folder">
<form method="POST" action="some action url " id="add-attendance"> 
    <table class="table_blue"  >
       <tr>       
           <td> <label for="start_time">Start Time</label></td>       
           <td><input type="text" value="" name="start_time" id="start_time"/></td>
       </tr>
       <tr>       
           <td> <label for="end_time">End Time</label></td>       
           <td> <input type="text" value="" name="end_time" id="end_time"/> </td>    
       </tr>
       <tr> 

我使用 xpath 做到了这一点,但它对我不起作用。这是我发送 key 的 Selenium 代码:

driver.find_element_by_xpath('[@id="unowacalendar"]/div/div/table/tbody/tr[2]/td[5]').send_keys("2019-12-03")

最佳答案

尝试定位输入元素。例如:

driver.find_element_by_id('start_time').send_keys('yourValue')

您可能需要等待,例如

WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.ID , 'start_time'))).send_keys('yourValue')

额外导入:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC

关于python - 如何在selenium python中的jquery日期时间选择器中选择日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55037837/

相关文章:

python - Keras 功能 API : "Error when checking input: expected input_1 to have 4 dimensions, but got array with shape (X, Y)"

python - 如何从图像的背景中删除感兴趣的区域?

python - 使用 Python : what exactly does the interpolation methods? 进行 cv2.resize

python - 用列表列表屏蔽两列(Pandas df)

python - Google Chrome 和 selenium webdriver 无法按预期工作

python - 删除Python中第一个实例后的字符串字符

python - 在 SQLAlchemy 中定义表时,如何将函数(依赖于其他列的表达式)定义为列的默认值?

python-3.x - 如何从没有扩展名python的路径中获取特定文件名

java - 如何在 Selenium WebDriver 中使用日期选择器选择特定日期

java - Selenium - 使用通配符从下拉列表中选择一个选项?