[英]Selenium through Python won't fill a field
I've been trying to use Selenium through Python to fill out a username and password field to allow a Twitter Authorization. 我一直在尝试通过Python使用Selenium填写用户名和密码字段以允许Twitter授权。 This should be a very basic task but it keeps giving me an error.
这应该是一个非常基本的任务,但它一直给我一个错误。 Here's the username field in HTML I want to fill:
这是我要填写的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>
Here's the HTML of the password field: 这是密码字段的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>
Here's my code: 这是我的代码:
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)
Fairly simple right? 相当简单吧? But the minute I run the code it throws an error when it tries to send_keys saying at the end of the error:
但是,当我运行代码时,它会在错误结束时尝试发送send_keys时抛出错误:
selenium.common.exceptions.WebDriverException: Message: TypeError - undefined is not a function (evaluating '_getTagName(currWindow).toLowerCase()')
Can anyone explain to me what's going here? 任何人都可以向我解释这里发生了什么? Why is it refusing to fill the fields?
为什么拒绝填补这些字段?
I tried to reproduce the error here, but the script works fine 我试图在这里重现错误,但脚本工作正常
a few days ago I got very strange errors with simple things, the solution was downgrade the webdriver 几天前,我用简单的事情得到了非常奇怪的错误,解决方案是降级webdriver
I'm using chromedriver 2.25 我正在使用chromedriver 2.25
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome(executable_path="/home/user/selenium/chromedriver2.25")
url = 'http://localhost/teste.html'
driver.get(url)
username_field = driver.find_element_by_id('username_or_email')
password_field = driver.find_element_by_id("password")
username_field.send_keys("MyEmail@gmail.com")
password_field.send_keys("SuperSecretPassword")
password_field.send_keys(Keys.ENTER)
html: 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>
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.