python如何避免访问对象不存在的属性_如何避免在selenium quit()上获取“NoneType”对象没有属性“path”?...

当运行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位。在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值