How to avoid getting `'NoneType' object has no attribute 'path'` on selenium quit()? How to avoid getting `'NoneType' object has no attribute 'path'` on selenium quit()? selenium selenium

How to avoid getting `'NoneType' object has no attribute 'path'` on selenium quit()?


It seems a bug in selenium 3.0 version

Update the quit() method definition in webdriver.py of firefox as follows (relative path: ..\Python27\Lib\site-packages\selenium\webdriver\firefox\webdriver.py):

change the following line in quit() method:

shutil.rmtree(self.profile.path) #which gives Nonetype has no attribute pathif self.profile.tempfolder is not None:    shutil.rmtree(self.profile.tempfolder)

to

if self.profile is not None:    shutil.rmtree(self.profile.path) # if self.profile is not None, then only rmtree method is called for path.    if self.profile.tempfolder is not None:        shutil.rmtree(self.profile.tempfolder) # if tempfolder is not None, then only rmtree is called for tempfolder.

Note: wherever self.profile is used, do the same. i.e., move the code to if condition as mentioned above.


In Selenium 3.0, profile and binary moved to firefox_options instead of their separate existence as firefox_profile and firefox_binary respectively in Selenium 2.0.

you can verify this in webdriver.py (of firefox) in __init__ method.

relevant code in __init__ method:

if firefox_options is None:    firefox_options = Options()    print dir(firefox_options) # you can refer binary and profile as part of firefox_options object.

Note: Observed that firefox_options.profile still giving None, which might be an issue to be fixed in selenium 3.0