简体   繁体   English

Selenium 未能使用 Python 在 Datepicker 字段上发送_keys

[英]Selenium failed to send_keys on Datepicker field using Python

When I want to send_keys to a readonly datepicker, I failed to input the date.当我想将_keys 发送到只读日期选择器时,我无法输入日期。 Here is thelink I try to remove the readonly first, clear, and send_keys.这是我尝试删除 readonly first、clear 和 send_keys 的链接

url="https://epaper.oeeee.com/epaper/A/html/2018-02/06/node_2637.htm"
driver.get(url)
d=driver.find_element_by_xpath("/html/body/div[1]/div/div[2]/input")
driver.execute_script('arguments[0].removeAttribute(\"readonly\")', d)
driver.find_element_by_xpath('/html/body/div[1]/div/div[2]/input').clear()
d.send_keys('2018-02-02')
d.send_keys(Keys.RETURN)

日期徽章图像

Could anyone tell me why?谁能告诉我为什么?

Many thanks非常感谢

First of all: I don't think it's read-only, I can regularely click on it, without changing anything.首先:我不认为它是只读的,我可以定期单击它,而无需更改任何内容。 then I don't think that you can clear and set it again as you might want.那么我认为您无法根据需要清除并重新设置它。 But there are quite a few solved datepicker problems, I will link you some with their respective solutions below:但是有很多已解决的日期选择器问题,我将在下面将一些与它们各自的解决方案联系起来:

How to change the date of a hidden element of a Datepicker using setAttribute method and Selenium with Python? 如何使用 setAttribute 方法和 Selenium 和 Python 更改 Datepicker 隐藏元素的日期?
Selenium calendar picker: I can click manually but Selenium cant click Selenium 日历选择器:我可以手动单击,但 Selenium 无法单击
How do I click on active day on date picker using selenium python? 如何使用 selenium python 在日期选择器上单击活动日期?

jQuery Datepicker jQuery 日期选择器

The jQuery Datepicker is tied to a standard form <input> field. jQuery Datepicker绑定到标准表单<input>字段。 Focus on the input (click, or use the tab key) to open an interactive calendar in a small overlay.专注于输入(单击或使用 Tab 键)以在小叠加层中打开交互式日历。 Choose a date, click elsewhere on the page (blur the input), or hit the Esc key to close.选择一个日期,单击页面上的其他位置(模糊输入),或按 Esc 键关闭。 If a date is chosen, feedback is shown as the input's value.如果选择了日期,则反馈显示为输入值。

If you observe the HTML DOM of theweb application it uses jQuery如果您观察web 应用程序HTML DOM ,它使用jQuery

"jquery": "/epaper/js/lib/jquery/jquery/1.10.1/jquery.js"

Now as per the HTML of the WebElement :现在根据WebElement的 HTML :

<input type="text" class="datepicker" readonly="readonly" data-date="2018-02-04">

Though the datepicker field is an <input> field, on click it calls the jQuery based datepicker class which doesn't accept any text input.虽然 datepicker 字段是一个<input>字段,但单击它会调用基于jQuerydatepicker class ,它不接受任何文本输入。 Hence send_keys() fails to send any character sequence to the <input> field.因此send_keys()无法将任何字符序列发送到<input>字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 ChromeDriver 和 Selenium 设置 max 属性时,无法使用 send_keys 将日期作为文本发送到 datepicker 字段 - Unable to send date as text to datepicker field using send_keys when max attribute is set using ChromeDriver and Selenium Python Selenium send_keys 到 email 输入字段 - Python Selenium send_keys to email input field 在selenium python webdriver中使用send_keys()发送三个键 - To send threekeys using send_keys() in selenium python webdriver 如何使用 selenium python 通过 send_keys 发送长文本 - how to send long text with send_keys using selenium python 使用.send_keys() 和 selenium python 无法在 FaceBook 2022 上上传照片 - Failed to upload photos on FaceBook 2022 using .send_keys() with selenium python 在Selenium Python中使用多个send_keys()无法正常工作 - Using multiple send_keys() in Selenium Python not working 如何使用 selenium 和 Python 调用 send_keys() - How to invoke send_keys() using selenium and Python 在 Python (Selenium) 中使用 send_keys 时删除方括号 - Removing square brackets when using send_keys in Python (Selenium) 使用XPATH / Send_Keys更改元素属性-Selenium Python - Change Element Attribute Using XPATH / Send_Keys - Selenium Python 在python中使用Selenium send_keys复制文本 - Copying text using selenium send_keys in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM