gpt4 book ai didi

python - selenium 'nonetype' 对象没有属性 'send_keys'

转载 作者:行者123 更新时间:2023-12-01 01:17:12 24 4
gpt4 key购买 nike

title='this is the title'

我想用 python/selenium 在网页中定位这一行:

<input id="subject" name="subject" maxlength="50" value="" class="nude error" type="text">

我将此代码与 python-selenium 一起使用(在 Debian 下):

title = driver.find_element_by_id("subject").clear()
title.send_keys(title)

我收到以下错误:

Traceback (most recent call last):

File "./basic0", line 49, in <module>
titre.send_keys(title)

AttributeError: 'NoneType' object has no attribute 'send_keys'

注意:当脚本因该错误而停止时,鼠标光标位于网页内的右侧位置;但我找不到 send_keys 来填写输入的方法

我也尝试过:

title = driver.find_element_by_xpath("div[contains(text(),'subject')]")

title = driver.find_element_by_xpath("//form[input/@id='subject']")

title = driver.find_element_by_xpath("//form[input[@name='subject']")

但它不起作用;此外,鼠标光标不在正确的位置。

然后我尝试了更高版本的 Selenium :

我在 Debian 下完全清除了 python-selenium 软件包(selenium v​​. 2.53)那么

pip install selenium==3.3.1

这一次,当我启动脚本时,它说 geckodriver 丢失:所以,

wget https://github.com/mozilla/geckodriver/releases/download/v0.23.0/geckodriver-v0.23.0-linux32.tar.gz

tar -xvzf geckodriver-v0.23.0-linux32.tar.gz

chmod 755 geckodriver (I also tried 777)

mv geckodriver /usr/local/bin/ (so it's in my PATH)

现在,当我启动脚本时,这是我收到的错误消息:

Traceback (most recent call last):

File "./basic0", line 13, in <module>
driver = webdriver.Firefox()

File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 155, in __init__
keep_alive=True)

File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)

File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)

File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 238, in execute
self.error_handler.check_response(response)

File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 193, in check_response
raise exception_class(message, screen, stacktrace)

selenium.common.exceptions.WebDriverException: Message: connection refuse

弹出firefox窗口,然后脚本停止时关闭

最佳答案

您已指定方法调用 (clear()),当您需要定义 WebElement 并调用方法时,该方法调用将 None 返回给 title 变量随后作为

title = driver.find_element_by_id("subject")
title.clear()
title.send_keys("title")

关于python - selenium 'nonetype' 对象没有属性 'send_keys',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54217451/

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