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']")
但它不起作用;此外,鼠标光标不在正确的位置。
然后我尝试了更高版本的硒:
我完全清除了 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 窗口弹出,然后在脚本停止时关闭