我想从 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/