当运行Selenium Webdriver Python脚本时,在执行self.driver.quit().
在try/except中封闭self.driver.quit()后得到一个'NoneType' object has no attribute 'path',即:$ cat demo_NoneType_attribute_error.py
# -*- coding: utf-8 -*-
from selenium import webdriver
import unittest
class TestPass(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
def test_pass(self):
pass
def tearDown(self):
print("doing: self.driver.quit()")
try:
self.driver.quit()
except AttributeError:
pass
if __name__ == "__main__":
unittest.main()
$ python demo_NoneType_attribute_error.py
doing: self.driver.quit()
'NoneType' object has no attribute 'path'
.
----------------------------------------------------------------------
Ran 1 test in 19.807s
OK
$
有人知道如何避免'NoneType' object has no attribute 'path'消息吗?在
注意:
由于这个问题在11月初就已经报告过了(请参见下面的url),它现在应该已经有了一个补丁-但是将selenium升级到pip的最新版本并没有消除它。在
环境:Selenium 3.0.2;Python2.7;Windows7上的Cygwin 32位。在