今天打开上次运行成功的.py文件,发现报错,报错信息如下:in/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Users/zhangyanyan/PycharmProjects/untitled1/baidu.py
Traceback (most recent call last):
File "/Users/zhangyanyan/PycharmProjects/untitled1/baidu.py", line 3, in
driver = webdriver.Firefox()
File "/Library/Python/2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 81, in __init__
self.binary, timeout)
File "/Library/Python/2.7/site-packages/selenium/webdriver/firefox/extension_connection.py", line 51, in __init__
self.binary.launch_browser(self.profile, timeout=timeout)
File "/Library/Python/2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser
self._wait_until_connectable(timeout=timeout)
File "/Library/Python/2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 98, in _wait_until_connectable
raise WebDriverException("The browser appears to have exited "
selenium.common.exceptions.WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.
Process finished with exit code 1
百度了一下,猜测应该是本机的firefox安装后未设置为非自动更新,导致firefox自动更新到最新版本,而selenium最新版并不支持firefox的最新版。
解决方法:
方法一:降firefox版本;
方法二:升selenium 的jar包;
方法三:下载与该版本selenium匹配的其他浏览器的驱动;
方法四:修改selenium兼容firefox版本的配置文件:
http://bbs.51testing.com/thread-1075662-1-1.html