|
18 | 18 | """The WebDriver implementation."""
|
19 | 19 |
|
20 | 20 | from abc import ABCMeta
|
21 |
| -import base64 |
| 21 | +from base64 import b64decode |
22 | 22 | import copy
|
23 | 23 | from contextlib import (contextmanager, asynccontextmanager)
|
24 |
| -import importlib |
| 24 | +from importlib import import_module |
25 | 25 | import pkgutil
|
26 | 26 | import warnings
|
27 | 27 | import sys
|
|
54 | 54 |
|
55 | 55 | cdp = None
|
56 | 56 |
|
57 |
| - |
58 | 57 | def import_cdp():
|
59 | 58 | global cdp
|
60 |
| - if cdp is None: |
61 |
| - cdp = importlib.import_module("selenium.webdriver.common.bidi.cdp") |
| 59 | + if not cdp: |
| 60 | + cdp = import_module("selenium.webdriver.common.bidi.cdp") |
62 | 61 |
|
63 | 62 |
|
64 | 63 | _W3C_CAPABILITY_NAMES = frozenset([
|
@@ -180,10 +179,10 @@ def __init__(self, command_executor='http://127.0.0.1:4444',
|
180 | 179 | """
|
181 | 180 | capabilities = {}
|
182 | 181 | _ignore_local_proxy = False
|
183 |
| - if options is not None: |
| 182 | + if options: |
184 | 183 | capabilities = options.to_capabilities()
|
185 | 184 | _ignore_local_proxy = options._ignore_local_proxy
|
186 |
| - if desired_capabilities is not None: |
| 185 | + if desired_capabilities: |
187 | 186 | if not isinstance(desired_capabilities, dict):
|
188 | 187 | raise WebDriverException("Desired Capabilities must be a dictionary")
|
189 | 188 | else:
|
@@ -240,7 +239,7 @@ def file_detector_context(self, file_detector_class, *args, **kwargs):
|
240 | 239 | try:
|
241 | 240 | yield
|
242 | 241 | finally:
|
243 |
| - if last_detector is not None: |
| 242 | + if last_detector: |
244 | 243 | self.file_detector = last_detector
|
245 | 244 |
|
246 | 245 | @property
|
@@ -304,7 +303,7 @@ def start_session(self, capabilities, browser_profile=None):
|
304 | 303 |
|
305 | 304 | # if capabilities is none we are probably speaking to
|
306 | 305 | # a W3C endpoint
|
307 |
| - if self.caps is None: |
| 306 | + if not self.caps: |
308 | 307 | self.caps = response.get('capabilities')
|
309 | 308 |
|
310 | 309 | # Double check to see if we have a W3C Compliant browser
|
@@ -356,7 +355,7 @@ def execute(self, driver_command, params=None):
|
356 | 355 | :Returns:
|
357 | 356 | The command's JSON response loaded into a dictionary object.
|
358 | 357 | """
|
359 |
| - if self.session_id is not None: |
| 358 | + if self.session_id: |
360 | 359 | if not params:
|
361 | 360 | params = {'sessionId': self.session_id}
|
362 | 361 | elif 'sessionId' not in params:
|
@@ -1256,7 +1255,7 @@ def get_screenshot_as_png(self):
|
1256 | 1255 |
|
1257 | 1256 | driver.get_screenshot_as_png()
|
1258 | 1257 | """
|
1259 |
| - return base64.b64decode(self.get_screenshot_as_base64().encode('ascii')) |
| 1258 | + return b64decode(self.get_screenshot_as_base64().encode('ascii')) |
1260 | 1259 |
|
1261 | 1260 | def get_screenshot_as_base64(self):
|
1262 | 1261 | """
|
@@ -1310,7 +1309,7 @@ def get_window_size(self, windowHandle='current'):
|
1310 | 1309 | else:
|
1311 | 1310 | size = self.execute(command, {'windowHandle': windowHandle})
|
1312 | 1311 |
|
1313 |
| - if size.get('value', None) is not None: |
| 1312 | + if size.get('value', None): |
1314 | 1313 | size = size['value']
|
1315 | 1314 |
|
1316 | 1315 | return {k: size[k] for k in ('width', 'height')}
|
@@ -1412,7 +1411,7 @@ def file_detector(self, detector):
|
1412 | 1411 | :Args:
|
1413 | 1412 | - detector: The detector to use. Must not be None.
|
1414 | 1413 | """
|
1415 |
| - if detector is None: |
| 1414 | + if not detector: |
1416 | 1415 | raise WebDriverException("You may not set a file detector that is null")
|
1417 | 1416 | if not isinstance(detector, FileDetector):
|
1418 | 1417 | raise WebDriverException("Detector has to be instance of FileDetector")
|
@@ -1560,13 +1559,13 @@ async def _get_bidi_connection(self):
|
1560 | 1559 | else:
|
1561 | 1560 | version, ws_url = self._get_cdp_details()
|
1562 | 1561 |
|
1563 |
| - if ws_url is None: |
| 1562 | + if not ws_url: |
1564 | 1563 | raise WebDriverException("Unable to find url to connect to from capabilities")
|
1565 | 1564 |
|
1566 | 1565 | cdp.import_devtools(version)
|
1567 | 1566 |
|
1568 | 1567 | global devtools
|
1569 |
| - devtools = importlib.import_module("selenium.webdriver.common.devtools.v{}".format(version)) |
| 1568 | + devtools = import_module("selenium.webdriver.common.devtools.v{}".format(version)) |
1570 | 1569 | async with cdp.open_cdp(ws_url) as conn:
|
1571 | 1570 | targets = await conn.execute(devtools.target.get_targets())
|
1572 | 1571 | target_id = targets[0].target_id
|
|
0 commit comments