gpt4 book ai didi

python - 通过 Python 的 Selenium 不会填充字段

转载 作者:太空狗 更新时间:2023-10-30 02:57:17 25 4
gpt4 key购买 nike

我一直在尝试通过 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)

很简单吧?但是在我运行代码的那一刻,它在尝试发送 key 时抛出错误,在错误结束时说:

selenium.common.exceptions.WebDriverException: Message: TypeError - undefined is not a function (evaluating '_getTagName(currWindow).toLowerCase()')

谁能给我解释一下这是怎么回事?为什么拒绝填写字段?

最佳答案

我试图重现这里的错误,但脚本运行正常

几天前,我在一些简单的事情上遇到了非常奇怪的错误,解决方案是降级 webdriver

我正在使用 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:

<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>

关于python - 通过 Python 的 Selenium 不会填充字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37648449/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com