【发布时间】:2019-12-25 15:24:45
【问题描述】:
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'
注意:当脚本因为这个错误而停止时,鼠标光标在网页内的右侧;但我找不到发送键来填写输入的方法
我也试过了:
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']")
但它不起作用;而且鼠标光标不在正确的位置。
然后我尝试了更高版本的硒:
我完全清除了 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窗口弹出,脚本停止后关闭
【问题讨论】: