diff --git a/py/generate_api_module_listing.py b/py/generate_api_module_listing.py index 638df7782843a..71605ca018d2e 100644 --- a/py/generate_api_module_listing.py +++ b/py/generate_api_module_listing.py @@ -21,7 +21,8 @@ file containing a listing of all modules in separate sections. The `api.rst` file is later used by `sphinx-autogen` to generate sphinx autodoc stub pages used in the Python API documentation. -See `py/tox.ini` for how it is invoked.""" +See `py/tox.ini` for how it is invoked. +""" import os import site diff --git a/py/pyproject.toml b/py/pyproject.toml index 0afd4194794fc..97b689585eec4 100644 --- a/py/pyproject.toml +++ b/py/pyproject.toml @@ -144,9 +144,26 @@ respect-gitignore = true target-version = "py39" [tool.ruff.lint] -extend-select = ["E4", "E7", "E9", "F", "I", "E501", "RUF022", "TID252"] +extend-select = ["D", "E4", "E7", "E9", "F", "I", "E501", "RUF022", "TID252"] fixable = ["ALL"] +# remove these as we cleanup docstrings +extend-ignore = [ + "D100", # Missing docstring in public module + "D101", # Missing docstring in public class + "D102", # Missing docstring in public method + "D103", # Missing docstring in public function + "D104", # Missing docstring in public package + "D105", # Missing docstring in magic method + "D107", # Missing docstring in `__init__` + "D205", # 1 blank line required between summary line and description + "D212", # Multi-line docstring summary should start at the first line + "D415", # First line should end with a period, question mark, or exclamation point + "D417", # Missing argument descriptions in the docstring for `__init__` +] [tool.ruff.format] docstring-code-format = true docstring-code-line-length = 120 + +[tool.ruff.lint.pydocstyle] +convention = "google" diff --git a/py/selenium/common/exceptions.py b/py/selenium/common/exceptions.py index 7e9b028a822fc..9d895598ba430 100644 --- a/py/selenium/common/exceptions.py +++ b/py/selenium/common/exceptions.py @@ -92,7 +92,8 @@ class NoSuchAttributeException(WebDriverException): class NoSuchShadowRootException(WebDriverException): """Thrown when trying to access the shadow root of an element when it does - not have a shadow root attached.""" + not have a shadow root attached. + """ class StaleElementReferenceException(WebDriverException): @@ -175,7 +176,8 @@ def __init__( class ElementNotInteractableException(InvalidElementStateException): """Thrown when an element is present in the DOM but interactions with that - element will hit another element due to paint order.""" + element will hit another element due to paint order. + """ def __init__( self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None @@ -194,7 +196,8 @@ class ElementNotSelectableException(InvalidElementStateException): class InvalidCookieDomainException(WebDriverException): """Thrown when attempting to add a cookie under a different domain than the - current URL.""" + current URL. + """ class UnableToSetCookieException(WebDriverException): @@ -207,7 +210,8 @@ class TimeoutException(WebDriverException): class MoveTargetOutOfBoundsException(WebDriverException): """Thrown when the target provided to the `ActionsChains` move() method is - invalid, i.e. out of document.""" + invalid, i.e. out of document. + """ class UnexpectedTagNameException(WebDriverException): @@ -254,7 +258,8 @@ class JavascriptException(WebDriverException): class NoSuchCookieException(WebDriverException): """No cookie matching the given path name was found amongst the associated - cookies of the current browsing context's active document.""" + cookies of the current browsing context's active document. + """ class ScreenshotException(WebDriverException): @@ -264,7 +269,8 @@ class ScreenshotException(WebDriverException): class ElementClickInterceptedException(WebDriverException): """The Element Click command could not be completed because the element receiving the events is obscuring the element that was requested to be - clicked.""" + clicked. + """ def __init__( self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None @@ -276,7 +282,8 @@ def __init__( class InsecureCertificateException(WebDriverException): """Navigation caused the user agent to hit a certificate warning, which is - usually the result of an expired or invalid TLS certificate.""" + usually the result of an expired or invalid TLS certificate. + """ class InvalidCoordinatesException(WebDriverException): @@ -285,7 +292,8 @@ class InvalidCoordinatesException(WebDriverException): class InvalidSessionIdException(WebDriverException): """Occurs if the given session id is not in the list of active sessions, - meaning the session either does not exist or that it's not active.""" + meaning the session either does not exist or that it's not active. + """ def __init__( self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None @@ -308,7 +316,8 @@ def __init__( class UnknownMethodException(WebDriverException): """The requested command matched a known URL but did not match any methods - for that URL.""" + for that URL. + """ class NoSuchDriverException(WebDriverException): diff --git a/py/selenium/webdriver/chromium/options.py b/py/selenium/webdriver/chromium/options.py index 9c6104a487f6c..41dda79eee535 100644 --- a/py/selenium/webdriver/chromium/options.py +++ b/py/selenium/webdriver/chromium/options.py @@ -100,7 +100,7 @@ def add_extension(self, extension: str) -> None: extract it to the ChromeDriver. Args: - extension: Path to the \\*.crx file. + extension: Path to the *.crx file. """ if extension: extension_to_add = os.path.abspath(os.path.expanduser(extension)) diff --git a/py/selenium/webdriver/chromium/webdriver.py b/py/selenium/webdriver/chromium/webdriver.py index 77b04c70db0ad..ba4c141ec941a 100644 --- a/py/selenium/webdriver/chromium/webdriver.py +++ b/py/selenium/webdriver/chromium/webdriver.py @@ -27,7 +27,8 @@ class ChromiumDriver(RemoteWebDriver): """Controls the WebDriver instance of ChromiumDriver and allows you to - drive the browser.""" + drive the browser. + """ def __init__( self, @@ -47,7 +48,6 @@ def __init__( service: Service object for handling the browser driver if you need to pass extra details. keep_alive: Whether to configure ChromiumRemoteConnection to use HTTP keep-alive. """ - self.service = service if service else ChromiumService() options = options if options else ChromiumOptions() diff --git a/py/selenium/webdriver/common/action_chains.py b/py/selenium/webdriver/common/action_chains.py index 6a3a4b37777ba..885546b84edb6 100644 --- a/py/selenium/webdriver/common/action_chains.py +++ b/py/selenium/webdriver/common/action_chains.py @@ -93,7 +93,8 @@ def perform(self) -> None: def reset_actions(self) -> None: """Clears actions that are already stored locally and on the remote - end.""" + end. + """ self.w3c_actions.clear_actions() for device in self.w3c_actions.devices: device.clear_actions() @@ -235,7 +236,6 @@ def move_by_offset(self, xoffset: int, yoffset: int) -> ActionChains: xoffset: X offset to move to, as a positive or negative integer. yoffset: Y offset to move to, as a positive or negative integer. """ - self.w3c_actions.pointer_action.move_by(xoffset, yoffset) self.w3c_actions.key_action.pause() @@ -247,7 +247,6 @@ def move_to_element(self, to_element: WebElement) -> ActionChains: Args: to_element: The WebElement to move to. """ - self.w3c_actions.pointer_action.move_to(to_element) self.w3c_actions.key_action.pause() @@ -262,7 +261,6 @@ def move_to_element_with_offset(self, to_element: WebElement, xoffset: int, yoff xoffset: X offset to move to, as a positive or negative integer. yoffset: Y offset to move to, as a positive or negative integer. """ - self.w3c_actions.pointer_action.move_to(to_element, int(xoffset), int(yoffset)) self.w3c_actions.key_action.pause() @@ -270,7 +268,6 @@ def move_to_element_with_offset(self, to_element: WebElement, xoffset: int, yoff def pause(self, seconds: float | int) -> ActionChains: """Pause all inputs for the specified duration in seconds.""" - self.w3c_actions.pointer_action.pause(seconds) self.w3c_actions.key_action.pause(int(seconds)) @@ -325,7 +322,6 @@ def scroll_to_element(self, element: WebElement) -> ActionChains: Args: element: Which element to scroll into the viewport. """ - self.w3c_actions.wheel_action.scroll(origin=element) return self @@ -337,7 +333,6 @@ def scroll_by_amount(self, delta_x: int, delta_y: int) -> ActionChains: delta_x: Distance along X axis to scroll using the wheel. A negative value scrolls left. delta_y: Distance along Y axis to scroll using the wheel. A negative value scrolls up. """ - self.w3c_actions.wheel_action.scroll(delta_x=delta_x, delta_y=delta_y) return self @@ -356,7 +351,6 @@ def scroll_from_origin(self, scroll_origin: ScrollOrigin, delta_x: int, delta_y: Raises: MoveTargetOutOfBoundsException: If the origin with offset is outside the viewport. """ - if not isinstance(scroll_origin, ScrollOrigin): raise TypeError(f"Expected object of type ScrollOrigin, got: {type(scroll_origin)}") diff --git a/py/selenium/webdriver/common/actions/input_device.py b/py/selenium/webdriver/common/actions/input_device.py index 37b6ff5c7061a..2cb97f8036e34 100644 --- a/py/selenium/webdriver/common/actions/input_device.py +++ b/py/selenium/webdriver/common/actions/input_device.py @@ -27,7 +27,6 @@ def __init__(self, name: Optional[str] = None): self.actions: list[Any] = [] def add_action(self, action: Any) -> None: - """""" self.actions.append(action) def clear_actions(self) -> None: diff --git a/py/selenium/webdriver/common/bidi/network.py b/py/selenium/webdriver/common/bidi/network.py index 9dfe802bbe14a..3eb91fe014863 100644 --- a/py/selenium/webdriver/common/bidi/network.py +++ b/py/selenium/webdriver/common/bidi/network.py @@ -116,7 +116,6 @@ def _on_request(self, event_name, callback): Returns: int: callback id """ - event = NetworkEvent(event_name) def _callback(event_data): @@ -155,7 +154,6 @@ def add_request_handler(self, event, callback, url_patterns=None, contexts=None) Returns: int: callback id """ - try: event_name = self.EVENTS[event] phase_name = self.PHASES[event] @@ -202,7 +200,6 @@ def remove_request_handler(self, event, callback_id): def clear_request_handlers(self): """Clear all request handlers from the network.""" - for event_name in self.subscriptions: net_event = NetworkEvent(event_name) for callback_id in self.subscriptions[event_name]: @@ -270,7 +267,6 @@ def __init__( def fail_request(self): """Fail this request.""" - if not self.request_id: raise ValueError("Request not found.") @@ -279,7 +275,6 @@ def fail_request(self): def continue_request(self, body=None, method=None, headers=None, cookies=None, url=None): """Continue after intercepting this request.""" - if not self.request_id: raise ValueError("Request not found.") @@ -307,7 +302,6 @@ def _continue_with_auth(self, username=None, password=None): Note: If username or password is None, it attempts auth with no credentials. """ - params = {} params["request"] = self.request_id diff --git a/py/selenium/webdriver/common/bidi/script.py b/py/selenium/webdriver/common/bidi/script.py index 851dfdfcc8d78..6583e211b6b38 100644 --- a/py/selenium/webdriver/common/bidi/script.py +++ b/py/selenium/webdriver/common/bidi/script.py @@ -283,7 +283,6 @@ def execute(self, script: str, *args) -> dict: Raises: WebDriverException: If the script execution fails. """ - if self.driver is None: raise WebDriverException("Driver reference is required for script execution") browsing_context_id = self.driver.current_window_handle diff --git a/py/selenium/webdriver/common/log.py b/py/selenium/webdriver/common/log.py index ba892a43231a9..2c931edcccefb 100644 --- a/py/selenium/webdriver/common/log.py +++ b/py/selenium/webdriver/common/log.py @@ -68,7 +68,6 @@ async def mutation_events(self) -> AsyncGenerator[dict[str, Any], None]: assert event["current_value"] == "" assert event["old_value"] == "display:none;" """ - page = self.cdp.get_session_context("page.enable") await page.execute(self.devtools.page.enable()) runtime = self.cdp.get_session_context("runtime.enable") @@ -105,7 +104,6 @@ async def add_js_error_listener(self) -> AsyncGenerator[dict[str, Any], None]: assert bool(error) assert error.exception_details.stack_trace.call_frames[0].function_name == "onmouseover" """ - session = self.cdp.get_session_context("page.enable") await session.execute(self.devtools.page.enable()) session = self.cdp.get_session_context("runtime.enable") @@ -128,7 +126,6 @@ async def add_listener(self, event_type) -> AsyncGenerator[dict[str, Any], None] driver.execute_script("console.log('I like cheese')") assert messages["message"] == "I love cheese" """ - from selenium.webdriver.common.bidi.console import Console session = self.cdp.get_session_context("page.enable") diff --git a/py/selenium/webdriver/common/options.py b/py/selenium/webdriver/common/options.py index 5a8a9935c8308..35426b23b059e 100644 --- a/py/selenium/webdriver/common/options.py +++ b/py/selenium/webdriver/common/options.py @@ -375,7 +375,8 @@ def default_capabilities(self): def ignore_local_proxy_environment_variables(self) -> None: """By calling this you will ignore HTTP_PROXY and HTTPS_PROXY from - being picked up and used.""" + being picked up and used. + """ self._ignore_local_proxy = True @@ -409,7 +410,8 @@ def add_argument(self, argument: str) -> None: def ignore_local_proxy_environment_variables(self) -> None: """By calling this you will ignore HTTP_PROXY and HTTPS_PROXY from - being picked up and used.""" + being picked up and used. + """ warnings.warn( "using ignore_local_proxy_environment_variables in Options has been deprecated, " "instead, create a Proxy instance with ProxyType.DIRECT to ignore proxy settings, " diff --git a/py/selenium/webdriver/common/proxy.py b/py/selenium/webdriver/common/proxy.py index b45d35432065a..eccd978f46d24 100644 --- a/py/selenium/webdriver/common/proxy.py +++ b/py/selenium/webdriver/common/proxy.py @@ -81,7 +81,8 @@ def __set__(self, obj, value): class Proxy: """Proxy contains information about proxy type and necessary proxy - settings.""" + settings. + """ proxyType = ProxyType.UNSPECIFIED autodetect = False diff --git a/py/selenium/webdriver/common/selenium_manager.py b/py/selenium/webdriver/common/selenium_manager.py index 125b4b3459fc0..6317220fb61c9 100644 --- a/py/selenium/webdriver/common/selenium_manager.py +++ b/py/selenium/webdriver/common/selenium_manager.py @@ -44,7 +44,6 @@ def binary_paths(self, args: list) -> dict: Returns: Dictionary of assets and their path. """ - args = [str(self._get_binary())] + args if logger.getEffectiveLevel() == logging.DEBUG: args.append("--debug") @@ -65,7 +64,6 @@ def _get_binary() -> Path: Raises: WebDriverException: If the platform is unsupported. """ - compiled_path = Path(__file__).parent.joinpath("selenium-manager") exe = sysconfig.get_config_var("EXE") if exe is not None: diff --git a/py/selenium/webdriver/common/service.py b/py/selenium/webdriver/common/service.py index 87773177dbaeb..e84a00a059637 100644 --- a/py/selenium/webdriver/common/service.py +++ b/py/selenium/webdriver/common/service.py @@ -124,12 +124,14 @@ def assert_process_still_running(self) -> None: def is_connectable(self) -> bool: """Establishes a socket connection to determine if the service running - on the port is accessible.""" + on the port is accessible. + """ return utils.is_connectable(self.port) def send_remote_shutdown_command(self) -> None: """Dispatch an HTTP request to the shutdown endpoint for the service in - an attempt to stop it.""" + an attempt to stop it. + """ try: request.urlopen(f"{self.service_url}/shutdown") except URLError: @@ -142,7 +144,6 @@ def send_remote_shutdown_command(self) -> None: def stop(self) -> None: """Stops the service.""" - if self.log_output not in {PIPE, subprocess.DEVNULL}: if isinstance(self.log_output, IOBase): self.log_output.close() diff --git a/py/selenium/webdriver/common/timeouts.py b/py/selenium/webdriver/common/timeouts.py index 008aef36ce8e6..ff4948f6d663b 100644 --- a/py/selenium/webdriver/common/timeouts.py +++ b/py/selenium/webdriver/common/timeouts.py @@ -62,7 +62,6 @@ def __init__(self, implicit_wait: float = 0, page_load: float = 0, script: float script: Number of seconds to wait for an asynchronous script to finish execution before throwing an error. """ - self._implicit_wait = self._convert(implicit_wait) self._page_load = self._convert(page_load) self._script = self._convert(script) diff --git a/py/selenium/webdriver/common/virtual_authenticator.py b/py/selenium/webdriver/common/virtual_authenticator.py index ed19df6e825ca..b3c951a98fdef 100644 --- a/py/selenium/webdriver/common/virtual_authenticator.py +++ b/py/selenium/webdriver/common/virtual_authenticator.py @@ -56,7 +56,6 @@ def __init__( Initialize VirtualAuthenticatorOptions object. """ - self.protocol: str = protocol self.transport: str = transport self.has_resident_key: bool = has_resident_key @@ -194,7 +193,8 @@ def __str__(self) -> str: def required_chromium_based_browser(func): """A decorator to ensure that the client used is a chromium based - browser.""" + browser. + """ @functools.wraps(func) def wrapper(self, *args, **kwargs): @@ -209,7 +209,8 @@ def wrapper(self, *args, **kwargs): def required_virtual_authenticator(func): """A decorator to ensure that the function is called with a virtual - authenticator.""" + authenticator. + """ @functools.wraps(func) @required_chromium_based_browser diff --git a/py/selenium/webdriver/firefox/firefox_binary.py b/py/selenium/webdriver/firefox/firefox_binary.py index a3efc036318bc..58e1bcb819c86 100644 --- a/py/selenium/webdriver/firefox/firefox_binary.py +++ b/py/selenium/webdriver/firefox/firefox_binary.py @@ -218,7 +218,8 @@ def _extract_and_check(self, profile, x86, amd64): def which(self, fname): """Returns the fully qualified path by searching Path of the given - name.""" + name. + """ for pe in os.environ["PATH"].split(os.pathsep): checkname = os.path.join(pe, fname) if os.access(checkname, os.X_OK) and not os.path.isdir(checkname): diff --git a/py/selenium/webdriver/firefox/firefox_profile.py b/py/selenium/webdriver/firefox/firefox_profile.py index bc783cd48c827..506253325dd66 100644 --- a/py/selenium/webdriver/firefox/firefox_profile.py +++ b/py/selenium/webdriver/firefox/firefox_profile.py @@ -148,7 +148,8 @@ def assume_untrusted_cert_issuer(self, value) -> None: @property def encoded(self) -> str: """Updates preferences and creates a zipped, base64 encoded string of - profile directory.""" + profile directory. + """ if self._desired_preferences: self.update_preferences() fp = BytesIO() @@ -162,7 +163,8 @@ def encoded(self) -> str: def _read_existing_userjs(self, userjs): """Reads existing preferences and adds them to desired preference - dictionary.""" + dictionary. + """ pref_pattern = re.compile(r'user_pref\("(.*)",\s(.*)\)') with open(userjs, encoding="utf-8") as f: for usr in f: @@ -239,7 +241,6 @@ def _addon_details(self, addon_path): "unpack": False, } # whether to unpack the addon """ - details = {"id": None, "unpack": False, "name": None, "version": None} def get_namespace_id(doc, url): @@ -263,7 +264,8 @@ def get_text(element): def parse_manifest_json(content): """Extracts the details from the contents of a WebExtensions - `manifest.json` file.""" + `manifest.json` file. + """ manifest = json.loads(content) try: id = manifest["applications"]["gecko"]["id"] diff --git a/py/selenium/webdriver/firefox/options.py b/py/selenium/webdriver/firefox/options.py index 809d3b7f59e05..86894e1924de3 100644 --- a/py/selenium/webdriver/firefox/options.py +++ b/py/selenium/webdriver/firefox/options.py @@ -57,7 +57,8 @@ def binary(self) -> FirefoxBinary: @deprecated("use binary_location instead") def binary(self, new_binary: Union[str, FirefoxBinary]) -> None: """Sets location of the browser binary, either by string or - ``FirefoxBinary`` instance.""" + ``FirefoxBinary`` instance. + """ if isinstance(new_binary, FirefoxBinary): new_binary = new_binary._start_cmd self.binary_location = str(new_binary) @@ -100,7 +101,8 @@ def profile(self) -> Optional[FirefoxProfile]: @profile.setter def profile(self, new_profile: Union[str, FirefoxProfile]) -> None: """Sets location of the browser profile to use, either by string or - ``FirefoxProfile``.""" + ``FirefoxProfile``. + """ if not isinstance(new_profile, FirefoxProfile): new_profile = FirefoxProfile(new_profile) self._profile = new_profile diff --git a/py/selenium/webdriver/firefox/webdriver.py b/py/selenium/webdriver/firefox/webdriver.py index 5b3078fe8f2da..560a7bdb0ad9c 100644 --- a/py/selenium/webdriver/firefox/webdriver.py +++ b/py/selenium/webdriver/firefox/webdriver.py @@ -49,7 +49,6 @@ def __init__( service: (Optional) service instance for managing the starting and stopping of the driver. keep_alive: Whether to configure remote_connection.RemoteConnection to use HTTP keep-alive. """ - self.service = service if service else Service() options = options if options else Options() @@ -131,7 +130,6 @@ def install_addon(self, path, temporary=False) -> str: Example: driver.install_addon("/path/to/firebug.xpi") """ - if os.path.isdir(path): fp = BytesIO() # filter all trailing slash found in path diff --git a/py/selenium/webdriver/ie/webdriver.py b/py/selenium/webdriver/ie/webdriver.py index 9029425b8e747..5209294f9f76b 100644 --- a/py/selenium/webdriver/ie/webdriver.py +++ b/py/selenium/webdriver/ie/webdriver.py @@ -27,7 +27,8 @@ class WebDriver(RemoteWebDriver): """Controls the IEServerDriver and allows you to drive Internet - Explorer.""" + Explorer. + """ def __init__( self, @@ -44,7 +45,6 @@ def __init__( service: (Optional) service instance for managing the starting and stopping of the driver. keep_alive: Whether to configure RemoteConnection to use HTTP keep-alive. """ - self.service = service if service else Service() options = options if options else Options() diff --git a/py/selenium/webdriver/remote/file_detector.py b/py/selenium/webdriver/remote/file_detector.py index 87944fdb9d93b..3691328bdab11 100644 --- a/py/selenium/webdriver/remote/file_detector.py +++ b/py/selenium/webdriver/remote/file_detector.py @@ -26,7 +26,8 @@ class FileDetector(metaclass=ABCMeta): """Used for identifying whether a sequence of chars represents the path to - a file.""" + a file. + """ @abstractmethod def is_local_file(self, *keys: AnyKey) -> Optional[str]: diff --git a/py/selenium/webdriver/remote/remote_connection.py b/py/selenium/webdriver/remote/remote_connection.py index 56d36c567656a..0c3bdab00bd7f 100644 --- a/py/selenium/webdriver/remote/remote_connection.py +++ b/py/selenium/webdriver/remote/remote_connection.py @@ -246,7 +246,6 @@ def get_remote_connection_headers(cls, parsed_url, keep_alive=False): parsed_url: The parsed url keep_alive: Is this a keep-alive connection (default: False) """ - headers = { "Accept": "application/json", "Content-Type": "application/json;charset=UTF-8", diff --git a/py/selenium/webdriver/remote/webdriver.py b/py/selenium/webdriver/remote/webdriver.py index c32a05b846009..17c7ac142f5fb 100644 --- a/py/selenium/webdriver/remote/webdriver.py +++ b/py/selenium/webdriver/remote/webdriver.py @@ -223,7 +223,6 @@ def __init__( WebElement. client_config: Custom client configuration to use. Defaults to None. """ - if options is None: raise TypeError( "missing 1 required keyword-only argument: 'options' (instance of driver `options.Options` class)" @@ -349,7 +348,6 @@ def start_session(self, capabilities: dict) -> None: Args: capabilities: A capabilities dict to start the session with. """ - caps = _create_caps(capabilities) try: response = self.execute(Command.NEW_SESSION, caps)["value"] @@ -709,7 +707,6 @@ def delete_cookie(self, name) -> None: Example: >>> driver.delete_cookie("my_cookie") """ - # firefox deletes all cookies when "" is passed as name if not name or name.isspace(): raise ValueError("Cookie name cannot be empty") @@ -959,7 +956,6 @@ def get_window_size(self, windowHandle: str = "current") -> dict: Example: >>> driver.get_window_size() """ - self._check_if_window_handle_is_current(windowHandle) size = self.get_window_rect() @@ -987,7 +983,6 @@ def get_window_position(self, windowHandle="current") -> dict: Example: >>> driver.get_window_position() """ - self._check_if_window_handle_is_current(windowHandle) position = self.get_window_rect() @@ -1018,7 +1013,6 @@ def set_window_rect(self, x=None, y=None, width=None, height=None) -> dict: >>> driver.set_window_rect(width=100, height=200) >>> driver.set_window_rect(x=10, y=10, width=100, height=200) """ - if (x is None and y is None) and (not height and not width): raise InvalidArgumentException("x and y or height and width need values") @@ -1179,7 +1173,8 @@ def browser(self): @property def _session(self): """Returns the BiDi session object for the current WebDriver - session.""" + session. + """ if not self._websocket_connection: self._start_bidi() diff --git a/py/selenium/webdriver/remote/webelement.py b/py/selenium/webdriver/remote/webelement.py index 24ba178745974..c90b48446660a 100644 --- a/py/selenium/webdriver/remote/webelement.py +++ b/py/selenium/webdriver/remote/webelement.py @@ -256,8 +256,6 @@ def send_keys(self, *value: str) -> None: >>> # Generally it's better to wrap the file path in one of the methods >>> # in os.path to return the actual path to support cross OS testing. >>> # file_input.send_keys(os.path.abspath("path/to/profilepic.gif")) - >>> # When using Cygwin, the path need to be provided in Windows format. - >>> # file_input.send_keys(f"C:/cygwin{os.path.abspath('path/to/profilepic.gif').replace('/', '\\')}") """ # transfer file to another machine only if remote driver is used # the same behaviour as for java binding diff --git a/py/selenium/webdriver/safari/options.py b/py/selenium/webdriver/safari/options.py index 02fce5a2c9740..87e63f8947177 100644 --- a/py/selenium/webdriver/safari/options.py +++ b/py/selenium/webdriver/safari/options.py @@ -30,11 +30,13 @@ class _SafariOptionsDescriptor: - `use_technology_preview` : When an attribute lookup happens, + Example: `self.automatic_inspection` `__get__` method does a dictionary look up in the dictionary `_caps` of `Options` class and returns the value of key `safari:automaticInspection` : When an attribute assignment happens, + Example: `self.automatic_inspection` = True `__set__` method sets/updates the value of the key `safari:automaticInspection` in `_caps` diff --git a/py/selenium/webdriver/support/color.py b/py/selenium/webdriver/support/color.py index f62f79d971d94..f263046b1b480 100644 --- a/py/selenium/webdriver/support/color.py +++ b/py/selenium/webdriver/support/color.py @@ -48,7 +48,6 @@ class Color: """Color conversion support class. Example: - :: from selenium.webdriver.support.color import Color diff --git a/py/selenium/webdriver/support/event_firing_webdriver.py b/py/selenium/webdriver/support/event_firing_webdriver.py index b113d1189bc1c..f98ab2cec9b50 100644 --- a/py/selenium/webdriver/support/event_firing_webdriver.py +++ b/py/selenium/webdriver/support/event_firing_webdriver.py @@ -37,7 +37,8 @@ def _wrap_elements(result, ef_driver): class EventFiringWebDriver: """A wrapper around an arbitrary WebDriver instance which supports firing - events.""" + events. + """ def __init__(self, driver: WebDriver, event_listener: AbstractEventListener) -> None: """Creates a new instance of the EventFiringWebDriver. diff --git a/py/selenium/webdriver/support/relative_locator.py b/py/selenium/webdriver/support/relative_locator.py index a8f5b715e6e4b..7f6e6717e9f6e 100644 --- a/py/selenium/webdriver/support/relative_locator.py +++ b/py/selenium/webdriver/support/relative_locator.py @@ -310,7 +310,8 @@ def near(self, element_or_locator: Union[WebElement, LocatorType, None] = None, def to_dict(self) -> dict: """Create a dict that will be passed to the driver to start searching - for the element.""" + for the element. + """ return { "relative": { "root": self.root, diff --git a/py/selenium/webdriver/support/select.py b/py/selenium/webdriver/support/select.py index 33a8459be47be..9453d05080fe5 100644 --- a/py/selenium/webdriver/support/select.py +++ b/py/selenium/webdriver/support/select.py @@ -30,7 +30,7 @@ def __init__(self, webelement: WebElement) -> None: webelement: SELECT element to wrap Example: - from selenium.webdriver.support.ui import Select \n + from selenium.webdriver.support.ui import Select Select(driver.find_element(By.TAG_NAME, "select")).select_by_index(2) """ if webelement.tag_name.lower() != "select": @@ -47,13 +47,15 @@ def options(self) -> list[WebElement]: @property def all_selected_options(self) -> list[WebElement]: """Returns a list of all selected options belonging to this select - tag.""" + tag. + """ return [opt for opt in self.options if opt.is_selected()] @property def first_selected_option(self) -> WebElement: """The first selected option in this select tag (or the currently - selected option in a normal select)""" + selected option in a normal select) + """ for opt in self.options: if opt.is_selected(): return opt diff --git a/py/selenium/webdriver/webkitgtk/options.py b/py/selenium/webdriver/webkitgtk/options.py index c6db4097c9502..4a5883ac719e2 100644 --- a/py/selenium/webdriver/webkitgtk/options.py +++ b/py/selenium/webdriver/webkitgtk/options.py @@ -63,7 +63,8 @@ def overlay_scrollbars_enabled(self, value) -> None: def to_capabilities(self): """Creates a capabilities with all the options that have been set and - returns a dictionary with everything.""" + returns a dictionary with everything. + """ caps = self._caps browser_options = {} diff --git a/py/selenium/webdriver/webkitgtk/webdriver.py b/py/selenium/webdriver/webkitgtk/webdriver.py index 0c81dc6f70c12..b50d25a9f08d7 100644 --- a/py/selenium/webdriver/webkitgtk/webdriver.py +++ b/py/selenium/webdriver/webkitgtk/webdriver.py @@ -40,7 +40,6 @@ def __init__( options: an instance of WebKitGTKOptions service: Service object for handling the browser driver if you need to pass extra details """ - options = options if options else Options() self.service = service if service else Service() self.service.path = DriverFinder(self.service, options).get_driver_path() @@ -51,7 +50,8 @@ def __init__( def quit(self): """Closes the browser and shuts down the WebKitGTKDriver executable - that is started when starting the WebKitGTKDriver.""" + that is started when starting the WebKitGTKDriver. + """ try: super().quit() except http_client.BadStatusLine: diff --git a/py/selenium/webdriver/wpewebkit/options.py b/py/selenium/webdriver/wpewebkit/options.py index 4a65b3bcd92a8..ff365791d0bcd 100644 --- a/py/selenium/webdriver/wpewebkit/options.py +++ b/py/selenium/webdriver/wpewebkit/options.py @@ -30,7 +30,8 @@ def __init__(self) -> None: @property def binary_location(self) -> str: """Returns the location of the browser binary otherwise an empty - string.""" + string. + """ return self._binary_location @binary_location.setter @@ -46,7 +47,8 @@ def binary_location(self, value: str) -> None: def to_capabilities(self): """Creates a capabilities with all the options that have been set and - returns a dictionary with everything.""" + returns a dictionary with everything. + """ caps = self._caps browser_options = {} diff --git a/py/selenium/webdriver/wpewebkit/webdriver.py b/py/selenium/webdriver/wpewebkit/webdriver.py index 5c10b5aa6e27c..6700727effbfb 100644 --- a/py/selenium/webdriver/wpewebkit/webdriver.py +++ b/py/selenium/webdriver/wpewebkit/webdriver.py @@ -40,7 +40,6 @@ def __init__( options: an instance of ``WPEWebKitOptions`` service: Service object for handling the browser driver if you need to pass extra details """ - options = options if options else Options() self.service = service if service else Service() self.service.path = DriverFinder(self.service, options).get_driver_path() @@ -51,7 +50,8 @@ def __init__( def quit(self): """Closes the browser and shuts down the WPEWebKitDriver executable - that is started when starting the WPEWebKitDriver.""" + that is started when starting the WPEWebKitDriver. + """ try: super().quit() except http_client.BadStatusLine: diff --git a/py/test/selenium/webdriver/common/bidi_webextension_tests.py b/py/test/selenium/webdriver/common/bidi_webextension_tests.py index 647f6002ad8af..7fe3fc9f376a4 100644 --- a/py/test/selenium/webdriver/common/bidi_webextension_tests.py +++ b/py/test/selenium/webdriver/common/bidi_webextension_tests.py @@ -70,7 +70,6 @@ class TestFirefoxWebExtension: def test_install_extension_path(self, driver, pages): """Test installing an extension from a directory path.""" - path = os.path.join(extensions, EXTENSION_PATH) ext_info = install_extension(driver, path=path) verify_extension_injection(driver, pages) @@ -78,7 +77,6 @@ def test_install_extension_path(self, driver, pages): def test_install_archive_extension_path(self, driver, pages): """Test installing an extension from an archive path.""" - path = os.path.join(extensions, EXTENSION_ARCHIVE_PATH) ext_info = install_extension(driver, archive_path=path) verify_extension_injection(driver, pages) @@ -86,7 +84,6 @@ def test_install_archive_extension_path(self, driver, pages): def test_install_base64_extension_path(self, driver, pages): """Test installing an extension from a base64 encoded string.""" - path = os.path.join(extensions, EXTENSION_ARCHIVE_PATH) with open(path, "rb") as file: base64_encoded = base64.b64encode(file.read()).decode("utf-8") @@ -97,7 +94,6 @@ def test_install_base64_extension_path(self, driver, pages): def test_install_unsigned_extension(self, driver, pages): """Test installing an unsigned extension.""" - path = os.path.join(extensions, "webextensions-selenium-example") ext_info = install_extension(driver, path=path) verify_extension_injection(driver, pages) @@ -105,7 +101,6 @@ def test_install_unsigned_extension(self, driver, pages): def test_install_with_extension_id_uninstall(self, driver, pages): """Test uninstalling an extension using just the extension ID.""" - path = os.path.join(extensions, EXTENSION_PATH) ext_info = install_extension(driver, path=path) extension_id = ext_info.get("extension") diff --git a/py/test/selenium/webdriver/common/example2.py b/py/test/selenium/webdriver/common/example2.py index aa31cfab4fb5b..fdc05df79d4d4 100644 --- a/py/test/selenium/webdriver/common/example2.py +++ b/py/test/selenium/webdriver/common/example2.py @@ -22,7 +22,8 @@ def test_search(driver): """This example shows how to use the page object pattern. For more information about this pattern, see: - https://github.com/SeleniumHQ/selenium/wiki/PageObjects""" + https://github.com/SeleniumHQ/selenium/wiki/PageObjects + """ google = GoogleOneBox(driver, "http://www.google.com") res = google.search_for("cheese") assert res.link_contains_match_for("Wikipedia") diff --git a/py/test/selenium/webdriver/common/interactions_tests.py b/py/test/selenium/webdriver/common/interactions_tests.py index a560b36669ef8..53d58af030d47 100644 --- a/py/test/selenium/webdriver/common/interactions_tests.py +++ b/py/test/selenium/webdriver/common/interactions_tests.py @@ -209,8 +209,7 @@ def test_sending_keys_to_element(driver, pages): def test_can_send_keys_between_clicks(driver, pages): - """ - For W3C, ensures that the correct number of pauses are given to the other + """For W3C, ensures that the correct number of pauses are given to the other input device. """ pages.load("javascriptPage.html") diff --git a/py/test/selenium/webdriver/common/interactions_with_device_tests.py b/py/test/selenium/webdriver/common/interactions_with_device_tests.py index 194e7fda76270..97637294403ca 100644 --- a/py/test/selenium/webdriver/common/interactions_with_device_tests.py +++ b/py/test/selenium/webdriver/common/interactions_with_device_tests.py @@ -194,8 +194,7 @@ def test_sending_keys_to_element_with_keyboard(driver, pages): def test_can_send_keys_between_clicks_with_keyboard(driver, pages): - """ - For W3C, ensures that the correct number of pauses are given to the other + """For W3C, ensures that the correct number of pauses are given to the other input device. """ pages.load("javascriptPage.html") diff --git a/py/test/selenium/webdriver/common/page_loader.py b/py/test/selenium/webdriver/common/page_loader.py index c6fe18d7ce177..f14cd166fff73 100644 --- a/py/test/selenium/webdriver/common/page_loader.py +++ b/py/test/selenium/webdriver/common/page_loader.py @@ -20,7 +20,8 @@ loaded, the @require_loaded decorator will make sure the page is loaded before the call is invoked. This pattern is also useful for waiting for certain asynchronous events -to happen before executing certain actions.""" +to happen before executing certain actions. +""" def require_loaded(func): diff --git a/py/test/selenium/webdriver/common/webserver.py b/py/test/selenium/webdriver/common/webserver.py index 82e0b239af26c..31805c5acdcdb 100644 --- a/py/test/selenium/webdriver/common/webserver.py +++ b/py/test/selenium/webdriver/common/webserver.py @@ -16,7 +16,8 @@ # under the License. """A simple web server for testing purpose. -It serves the testing html pages that are needed by the webdriver unit tests.""" +It serves the testing html pages that are needed by the webdriver unit tests. +""" import contextlib import logging