环境:
1、ubuntu系统
2、selenium 3.141.0
3、火狐浏览器驱动 geckodriver-v0.24.0-linux32
在Python中执行脚本:
from selenium import webdriver
browser = webdriver.Firefox()
结果提示:Message: Unable to find a matching set of capabilities
Traceback (most recent call last):
File "/home/yanner/seleniumtest/sousuo.py", line 2, in <module>
browser = webdriver.Firefox()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
keep_alive=True)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities
解决方法:更新firefox浏览器
1、从浏览器进入firefox官网下载最新版本firefox-67.0.4.tar.bz2
2、进入下载目录,将该文件解压。
3、打开终端模拟器,进入到下载目录,输入安装命令行。
root@yanner-VirtualBox:/home/yanner/下载/firefox# sudo apt-get install firefox
更新后,Firefox 52.0.2
再次执行脚本,正常打开浏览器:
from selenium import webdriver
browser = webdriver.Firefox()
但是,打开网页失败,提示Message: connection refused:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get("http://www.baidu.com")
browser.find_element_by_id("kw").send_keys("selenium")
browser.find_element_by_id("su").click()
browser.quit()
研究了半天,将驱动geckodriver-v0.24.0-linux32降版本,将目录/usr/local/bin下的驱动geckodriver删掉,下载了geckodriver-v0.17.0-linux32解压复制到/usr/local/bin下(可以参考上一篇文章https://www.cnblogs.com/yanner/p/11077762.html),
再次运行上面的脚本,正常打开!