python的selenium“send_keys”与铬司机滴字符 [英] python's selenium "send_keys" with chrome driver drops characters
问题描述
我使用Python的selenium包( https://pypi.python.org/pypi/selenium ) Windows 7
当我尝试登录我的Facebook帐户时,我使用 send_keys
命令,例如
elem = browser.find_element_by_name(email)
elem.send_keys(email);
elem = browser.find_element_by_name(pass)
elem.send_keys(password);
登录失败显然是因为第二个 send_keys
密码的第一个字符(我通过直接将密码字符发送到电子邮件字段发现了这个问题。
发生了什么事?为什么硒不能做到这么简单将密钥发送到输入字段?
这是由Facebook编码的一种保护措施,用于拒绝自动脚本?
试图发送整个字母表并获得这:
abcdefghijklmnopqrstuvwxyzBCDFGIKLNOQSTWX
注意有多少个字符不存在...
更新
显然问题是
如果我发送以下简单代码
browser = webdriver.Chrome()
browser.get(https://www.google.com)#加载页面
elem = browser.find_element_by_name(q )#查找查询框
query =ABCDEFGHIJKLMNOPQRSTUVWXYZ
elem.send_keys(查询)
使用chrome驱动程序我得到
BCDFGIKLNOQSTWX
注意A,E,H ... Y,Z缺少
用firefox驱动(替换 browser = webdriver.Chrome() code> with
browser = webdriver.Firefox()
我得到:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
Chrome浏览器中存在一些错误: https://code.google.com/p/chromedriver/issues/detail?id=435
当键盘配置为非英语语言,或者如果web驱动程序进程和chrome显示屏在不同的语言/环境下运行时(例如,当通过从一台主机到另一台主机的远程显示器等时),问题就会出现。 )
I am using selenium package with Python (https://pypi.python.org/pypi/selenium) with Windows 7.
When I try to login to my facebook account I use the send_keys
command, e.g.
elem = browser.find_element_by_name("email")
elem.send_keys(email);
elem = browser.find_element_by_name("pass")
elem.send_keys(password);
Login fails apparently because the second send_keys
drops the first character of the password (I found this by directly sending the password characters to the email field.
What's going on? Why can't selenium do something so simple as sending keys to an input field? Is this some kind of a protection measure coded by Facebook to reject automatic scripting?
Tried to send the whole alphabet and got this:
abcdefghijklmnopqrstuvwxyzBCDFGIKLNOQSTWX
Notice how many characters are missing...
Update
Apparently the problem has nothing to do with facebook but to the chrome driver.
If I send the following simple code
browser = webdriver.Chrome()
browser.get("https://www.google.com") # Load page
elem = browser.find_element_by_name("q") # Find the query box
query= "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
elem.send_keys(query)
With chrome driver I get
BCDFGIKLNOQSTWX
Notice how A, E, H ... Y, Z are missing
With firefox driver (replacing browser = webdriver.Chrome()
with browser = webdriver.Firefox()
I get:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
Looks like there are (were) some bugs in the Chrome webdriver: https://code.google.com/p/chromedriver/issues/detail?id=435
The core of the problem looks to be when either the keyboard is configured for a non-English language, or if the webdriver process and the chrome display are running in different language/environments (e.g., when going through a remote display from one host to another, etc.)
这篇关于python的selenium“send_keys”与铬司机滴字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!