I'm trying to subclass the Chrome WebDriver to include some initialization and cleanup code, but then Python complains that the created object is set to None:
import glob
import selenium
import subprocess
from selenium.webdriver.common.by import By
class WebDriver(selenium.webdriver.Chrome):
    def __init__(self, url, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.url = url
    def __enter__(self):
        self.get(self.url)
        self.implicitly_wait(15)
    def __exit__(self, type, value, traceback):
        self.quit()
        for path in glob.glob('/tmp/.org.chromium.Chromium.*'):
            subprocess.run(['rm', '-rf', path], check=True)
with WebDriver('https://google.com') as driver:
    driver.find_element(By.ID, 'lst-ib').send_keys('Search')
Running the code with Python 3:
$ python3 test.py
Traceback (most recent call last):
  File "test.py", line 43, in <module>
    driver.find_element(By.ID, 'lst-ib').send_keys('Search')
AttributeError: 'NoneType' object has no attribute 'find_element'
 
     
    