使用 Selenium/Python 输入数据不起作用
Inputing date using Selenium/Python does not work
我正尝试在 Python 中使用 Selenium 填写表格。文本字段工作正常,但是当我使用发送文本到日期字段时,它不能正常工作。好像是输入空格。
代码如下:
h_dob_field = firefox.find_element_by_id(
'MainContent_txtHDateofBirth'
).send_keys('01012001')
控制台日志显示正在发送:
2016-02-16 17:24:38,934 - DEBUG - POST http://127.0.0.1:45672/hub/session/283ad883-ac6a-4f25-b747-26f61cb897fc/element/{cc4f0cd1-ef8a-41f5-bf0e-615b6a970031}/value {"id": "{cc4f0cd1-ef8a-41f5-bf0e-615b6a970031}", "sessionId": "283ad883-ac6a-4f25-b747-26f61cb897fc", "value": ["2", "1", "3", "1", "9", "6", "2"]}
我的 html 目标是:
<input class="" name="ctl00$MainContent$txtHDateofBirth" id="MainContent_txtHDateofBirth" type="text">
我要输入数据的页面是 here。
我读过一些其他回答,说我应该尝试调用 click() 方法。我这样做了,但没有效果。我正在使用 firefox 驱动程序; Python3.4,在LinuxMint上,是selenium的最新版本。
您可以根据您的发现使用 fiddler to capture the request for when you fill out the form manually and write a custom web request。
另一种选择是使用 selenium IDE Firefox 扩展 (link) 并使用它的记录功能来记录您的步骤并为您制作。
我正尝试在 Python 中使用 Selenium 填写表格。文本字段工作正常,但是当我使用发送文本到日期字段时,它不能正常工作。好像是输入空格。
代码如下:
h_dob_field = firefox.find_element_by_id(
'MainContent_txtHDateofBirth'
).send_keys('01012001')
控制台日志显示正在发送:
2016-02-16 17:24:38,934 - DEBUG - POST http://127.0.0.1:45672/hub/session/283ad883-ac6a-4f25-b747-26f61cb897fc/element/{cc4f0cd1-ef8a-41f5-bf0e-615b6a970031}/value {"id": "{cc4f0cd1-ef8a-41f5-bf0e-615b6a970031}", "sessionId": "283ad883-ac6a-4f25-b747-26f61cb897fc", "value": ["2", "1", "3", "1", "9", "6", "2"]}
我的 html 目标是:
<input class="" name="ctl00$MainContent$txtHDateofBirth" id="MainContent_txtHDateofBirth" type="text">
我要输入数据的页面是 here。
我读过一些其他回答,说我应该尝试调用 click() 方法。我这样做了,但没有效果。我正在使用 firefox 驱动程序; Python3.4,在LinuxMint上,是selenium的最新版本。
您可以根据您的发现使用 fiddler to capture the request for when you fill out the form manually and write a custom web request。
另一种选择是使用 selenium IDE Firefox 扩展 (link) 并使用它的记录功能来记录您的步骤并为您制作。