def get_driver_instance(): b = webdriver.Chrome(service=Service(driver_path), options=options) b.implicitly_wait(10) b.set_window_position(0, 0) b.set_window_rect(0, 0, 1000, 600) return b with get_driver_instance() as b: b.get("https://www.python.org") time.sleep(3)