|
1 |
| -from contextlib import contextmanager |
| 1 | +""" |
| 2 | +The SeleniumBase Driver as a Python Context Manager or a returnable object. |
| 3 | +########################################################################### |
| 4 | +
|
| 5 | +The SeleniumBase Driver as a context manager: |
| 6 | +Usage --> ``with Driver() as driver:`` |
| 7 | +Usage example --> |
| 8 | + from seleniumbase import Driver |
| 9 | + with Driver() as driver: |
| 10 | + driver.get("https://google.com/ncr") |
| 11 | + # The browser exits automatically after the "with" block ends. |
| 12 | +
|
| 13 | +########################################################################### |
| 14 | +# Above: The driver as a context manager. (Used with a "with" statement.) # |
| 15 | +# ----------------------------------------------------------------------- # |
| 16 | +# Below: The driver as a returnable object. (Used with "return" command.) # |
| 17 | +########################################################################### |
| 18 | +
|
| 19 | +The SeleniumBase Driver as a returnable object: |
| 20 | +Usage --> ``driver = Driver()`` |
| 21 | +Usage example --> |
| 22 | + from seleniumbase import Driver |
| 23 | + driver = Driver() |
| 24 | + driver.get("https://google.com/ncr") |
| 25 | +
|
| 26 | +########################################################################### |
| 27 | +""" |
2 | 28 |
|
3 | 29 |
|
4 |
| -@contextmanager # Usage: -> ``with Driver() as driver:`` |
5 | 30 | def Driver(
|
6 | 31 | browser=None, # Choose from "chrome", "edge", "firefox", or "safari".
|
7 | 32 | headless=None, # The original headless mode for Chromium and Firefox.
|
@@ -51,13 +76,6 @@ def Driver(
|
51 | 76 | undetected=None, # Duplicate of "undetectable" to avoid confusion.
|
52 | 77 | uc_sub=None, # Duplicate of "uc_subprocess" to avoid confusion.
|
53 | 78 | ):
|
54 |
| - """ Context Manager for the SeleniumBase Driver Manager. |
55 |
| - Usage example: |
56 |
| - from seleniumbase import Driver |
57 |
| - with Driver() as driver: |
58 |
| - driver.get("https://google.com/ncr") |
59 |
| - # The browser exits automatically after the "with" block ends. |
60 |
| - """ |
61 | 79 | import sys
|
62 | 80 | from seleniumbase.fixtures import constants
|
63 | 81 |
|
@@ -357,10 +375,4 @@ def Driver(
|
357 | 375 | device_pixel_ratio=d_p_r,
|
358 | 376 | browser=browser_name,
|
359 | 377 | )
|
360 |
| - try: |
361 |
| - yield driver |
362 |
| - finally: |
363 |
| - try: |
364 |
| - driver.quit() |
365 |
| - except Exception: |
366 |
| - pass |
| 378 | + return driver |
0 commit comments