From 6002d146afca66129ab835eef993b7e95c676bb3 Mon Sep 17 00:00:00 2001 From: Sandeep Suryaprasad <26169602+sandeepsuryaprasad@users.noreply.github.com> Date: Tue, 4 Jul 2023 19:39:57 +0530 Subject: [PATCH] [py] added type hints to `SwitchTo` class (#12296) * [py] added type hints to SwitchTo class * [py] fixed lynting error --- py/selenium/webdriver/remote/switch_to.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/py/selenium/webdriver/remote/switch_to.py b/py/selenium/webdriver/remote/switch_to.py index cc2f686f0e38e..4621b111a24d5 100644 --- a/py/selenium/webdriver/remote/switch_to.py +++ b/py/selenium/webdriver/remote/switch_to.py @@ -15,6 +15,9 @@ # specific language governing permissions and limitations # under the License. +from typing import Optional +from typing import Union + from selenium.common.exceptions import NoSuchElementException from selenium.common.exceptions import NoSuchFrameException from selenium.common.exceptions import NoSuchWindowException @@ -26,7 +29,7 @@ class SwitchTo: - def __init__(self, driver): + def __init__(self, driver) -> None: import weakref self._driver = weakref.proxy(driver) @@ -65,7 +68,7 @@ def default_content(self) -> None: """ self._driver.execute(Command.SWITCH_TO_FRAME, {"id": None}) - def frame(self, frame_reference) -> None: + def frame(self, frame_reference: Union[str, int, WebElement]) -> None: """Switches focus to the specified frame, by index, name, or webelement. @@ -91,7 +94,7 @@ def frame(self, frame_reference) -> None: self._driver.execute(Command.SWITCH_TO_FRAME, {"id": frame_reference}) - def new_window(self, type_hint=None) -> None: + def new_window(self, type_hint: Optional[str] = None) -> None: """Switches to a new top-level browsing context. The type hint can be one of "tab" or "window". If not specified the @@ -116,7 +119,7 @@ def parent_frame(self) -> None: """ self._driver.execute(Command.SWITCH_TO_PARENT_FRAME) - def window(self, window_name) -> None: + def window(self, window_name: str) -> None: """Switches focus to the specified window. :Args: @@ -129,7 +132,7 @@ def window(self, window_name) -> None: """ self._w3c_window(window_name) - def _w3c_window(self, window_name): + def _w3c_window(self, window_name: str) -> None: def send_handle(h): self._driver.execute(Command.SWITCH_TO_WINDOW, {"handle": h})