用于firefox的Python selenium webdriver无法一致地打开

时间:2016-04-07 11:27:16

标签: python selenium firefox

我使用以下python脚本打开并启动Firefox浏览器。它有时会起作用,而在其他情况下,它会出错。我在这里做错了什么?

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()

我得到的错误是这种情况不会一直发生。

 Traceback (most recent call last):
File "seleniumtest.py", line 4, in <module>
driver = webdriver.Firefox()
File "C:\Python27\lib\site-packages\selenium-2.53.1-py2.7.egg\selenium\webdrier\firefox\webdriver.py", line 103, in __init__
self.binary, timeout)
File "C:\Python27\lib\site-packages\selenium-2.53.1-py2.7.egg\selenium\webdrier\firefox\extension_connection.py", line 49, in __init__
self.profile.add_extension()
File "C:\Python27\lib\site-packages\selenium-2.53.1-py2.7.egg\selenium\webdrier\firefox\firefox_profile.py", line 91, in add_extension
self._install_extension(extension)
File "C:\Python27\lib\site-packages\selenium-2.53.1-py2.7.egg\selenium\webdrier\firefox\firefox_profile.py", line 287, in _install_extension
shutil.rmtree(tmpdir)
File "C:\Python27\lib\shutil.py", line 247, in rmtree
rmtree(fullname, ignore_errors, onerror)
File "C:\Python27\lib\shutil.py", line 256, in rmtree
onerror(os.rmdir, path, sys.exc_info())
File "C:\Python27\lib\shutil.py", line 254, in rmtree
os.rmdir(path)

WindowsError: [Error 145] The directory is not empty: 'c:\\users\\cgdc\\appata\\local\\temp\\tmpqirkg6.webdriver.xpi\\components'

1 个答案:

答案 0 :(得分:1)

检查您的文件是否只有只读标志。

参考: -

python shutil.rmtree throwing errors

希望它会对你有所帮助:)。