python执行selenium报错
python + unittest + HTMLTestRunner 执行suite用例报错
Traceback (most recent call last):
File "C:/ws/Selenium-Framework-master/testsuites/TestRunner.py", line 48, in <module>
runner.run(createsuite1())
File "C:\Python27\Lib\HTMLTestRunner.py", line 628, in run
test(result)
File "C:\Python27\Lib\unittest\suite.py", line 70, in __call__
return self.run(*args, **kwds)
File "C:\Python27\Lib\unittest\suite.py", line 100, in run
self._handleClassSetUp(test, result)
File "C:\Python27\Lib\unittest\suite.py", line 153, in _handleClassSetUp
self._addClassOrModuleLevelException(result, e, errorName)
File "C:\Python27\Lib\unittest\suite.py", line 198, in _addClassOrModuleLevelException
result.addError(error, sys.exc_info())
File "C:\Python27\Lib\HTMLTestRunner.py", line 584, in addError
output = self.complete_output()
File "C:\Python27\Lib\HTMLTestRunner.py", line 558, in complete_output
return self.outputBuffer.getvalue()
AttributeError: '_TestResult' object has no attribute 'outputBuffer'
百度搜索,不能解决问题,谷歌无法上网,只能想办法单独执行用例,报错:
Failure
Traceback (most recent call last):
File "C:\Python27\Lib\unittest\suite.py", line 146, in _handleClassSetUp
setUpClass()
File "C:\ws\Selenium-Framework-master\testsuites\test_baidu_search.py", line 16, in setUpClass
cls.driver = browse.open_browser(cls)
File "C:\ws\Selenium-Framework-master\framework\browser_engine.py", line 45, in open_browser
driver.maximize_window()
File "C:\Users\Administrator\PycharmProjects\untitled\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 728, in maximize_window
self.execute(command, {"windowHandle": "current"})
File "C:\Users\Administrator\PycharmProjects\untitled\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 314, in execute
self.error_handler.check_response(response)
File "C:\Users\Administrator\PycharmProjects\untitled\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
WebDriverException: Message: unknown error: cannot get automation extension
from unknown error: page could not be found: chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/_generated_background_page.html
(Session info: chrome=66.0.3359.181)
(Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 6.1.7601 SP1 x86_64)
查找原来是chrome 浏览器和chromedriver 版本不一致
虽然我下载了和chrome浏览器一致的chromdriver,也放到c盘widows目录环境变量中去了,但是在代码中指定的chromedriver 位置中存放的还是旧版本。更换好对应版本的chromedriver后就好了
我有另外一篇博客介绍怎么获取正确的chromdirver版本 : http://www.cnblogs.com/testway/p/8041937.html