【发布时间】:2016-06-06 01:29:35
【问题描述】:
我一直在尝试通过 Python 使用 Selenium 来填写用户名和密码字段以允许 Twitter 授权。这应该是一项非常基本的任务,但它一直给我一个错误。这是我要填写的 HTML 中的用户名字段:
<div class="row user ">
<label for="username_or_email" tabindex="-1">Username or email</label>
<input aria-required="true" autocapitalize="off" autocorrect="off" autofocus="autofocus" class="text" id="username_or_email" name="session[username_or_email]" type="text" value="">
</div>
这是密码字段的 HTML:
<div class="row password ">
<label for="password" tabindex="-1">Password</label>
<input aria-required="true" class="password text" id="password" name="session[password]" type="password" value="">
</div>
这是我的代码:
username_field = browser.find_element_by_id("username_or_email")
password_field = browser.find_element_by_id("password")
username_field.send_keys("MyEmail@gmail.com")
password_field.send_keys("SuperSecretPassword")
password_field.send_keys(Keys.ENTER)
很简单吧?但是在我运行代码的那一刻,当它尝试 send_keys 在错误结束时说:
selenium.common.exceptions.WebDriverException: Message: TypeError - undefined is not a function (evaluating '_getTagName(currWindow).toLowerCase()')
谁能给我解释一下这里发生了什么?为什么它拒绝填写字段?
【问题讨论】:
-
我很确定缺少代码,您要使用什么浏览器?
-
我正在为此使用 PhantomJS。 browser = webdriver.PhantomJS(executable_path='PATH TO PHANTOMJS')
-
我怀疑它的
for标签在那里发挥了一些作用。关注github.com/detro/ghostdriver/issues/450 可能会有所帮助。
标签: python selenium twitter phantomjs