Adding __enter__ and __exit__ methods to python webdriver will make it as context manger
Eliminates the use of quit(), as with file handling in python. Remains backward compatible with usual way of calling quit saperately
with webdriver.Chrome() as driver:
driver.get("some/address")
driver.execute_script("some_js_script")
class WebDriver:
...
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
do_something_with_the_execeptions_if_any(exc_type, exc_val, exc_tb)
self.quit()
@lmtierney @AutomatedTester @Dude-X
Do you have any thoughts?
@dumbPy This has been implemented since version 3.13.0. The latest version has context manager support.
In a testing context, I find a context manager useless, but other forms of scripting may be useful
Ah ok, so this already exists @Dude-X? We could close this feature request, just confirming.
@diemol Yes please close.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
@diemol Yes please close.