【发布时间】:2020-01-11 16:18:19
【问题描述】:
我想指定开始日期和结束日期。
我无法更改默认日期,因为输入框是只读的。或者,我必须通过单击日历来选择日期。不知道该怎么做。有没有办法将键发送到只读输入框?
两个输入框的来源如下:
<div class="date-from">
<h3>From</h3>
<input type="text" readonly="readonly" value="Jan 11, 2020">
<button class="icon la-Calendar"></button>
</div>
<div class="date-to">
<h3>To</h3>
<input type="text" readonly="readonly" value="Jan 11, 2020">
<button class="icon la-Calendar"></button>
</div>
我的以下代码收到“消息:无效元素状态”错误。谢谢!
browser.find_element_by_xpath('//*[@id="bpcg9kk"]/div/div[3]/div[1]/div[2]/div[1]/div[2]/div[1]/input').clear()
browser.find_element_by_xpath('//*[@id="bpcg9kk"]/div/div[3]/div[1]/div[2]/div[1]/div[2]/div[1]/input').send_keys("Jan 01,2019")
[更新] 快到了。使用以下代码。请求日期已成功更改。结束日期有问题。请求日期也出现在结束日期框中。
element = browser.find_element_by_xpath('//*[@id="bpcg9kk"]/div/div[3]/div[1]/div[2]/div[1]/div[2]/div[1]/input')
browser.execute_script("arguments[0].removeAttribute('readonly','readonly')",element)
element.clear()
element.send_keys("Jan 01, 2019")
time.sleep(5)
element2 = browser.find_element_by_xpath('//*[@id="bpcg9kk"]/div/div[3]/div[1]/div[2]/div[1]/div[2]/div[2]/input')
browser.execute_script("arguments[0].removeAttribute('readonly','readonly')",element2)
element2.clear()
element2.send_keys("Dec 31, 2019")
【问题讨论】:
-
清除字段出现问题。如果您无法使用 clear() 清除。你可以试试 Action 类
标签: python selenium selenium-webdriver