Skip to content

Commit 6002d14

Browse files
[py] added type hints to SwitchTo class (#12296)
* [py] added type hints to SwitchTo class * [py] fixed lynting error
1 parent 4b9a8ea commit 6002d14

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

py/selenium/webdriver/remote/switch_to.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18+
from typing import Optional
19+
from typing import Union
20+
1821
from selenium.common.exceptions import NoSuchElementException
1922
from selenium.common.exceptions import NoSuchFrameException
2023
from selenium.common.exceptions import NoSuchWindowException
@@ -26,7 +29,7 @@
2629

2730

2831
class SwitchTo:
29-
def __init__(self, driver):
32+
def __init__(self, driver) -> None:
3033
import weakref
3134

3235
self._driver = weakref.proxy(driver)
@@ -65,7 +68,7 @@ def default_content(self) -> None:
6568
"""
6669
self._driver.execute(Command.SWITCH_TO_FRAME, {"id": None})
6770

68-
def frame(self, frame_reference) -> None:
71+
def frame(self, frame_reference: Union[str, int, WebElement]) -> None:
6972
"""Switches focus to the specified frame, by index, name, or
7073
webelement.
7174
@@ -91,7 +94,7 @@ def frame(self, frame_reference) -> None:
9194

9295
self._driver.execute(Command.SWITCH_TO_FRAME, {"id": frame_reference})
9396

94-
def new_window(self, type_hint=None) -> None:
97+
def new_window(self, type_hint: Optional[str] = None) -> None:
9598
"""Switches to a new top-level browsing context.
9699
97100
The type hint can be one of "tab" or "window". If not specified the
@@ -116,7 +119,7 @@ def parent_frame(self) -> None:
116119
"""
117120
self._driver.execute(Command.SWITCH_TO_PARENT_FRAME)
118121

119-
def window(self, window_name) -> None:
122+
def window(self, window_name: str) -> None:
120123
"""Switches focus to the specified window.
121124
122125
:Args:
@@ -129,7 +132,7 @@ def window(self, window_name) -> None:
129132
"""
130133
self._w3c_window(window_name)
131134

132-
def _w3c_window(self, window_name):
135+
def _w3c_window(self, window_name: str) -> None:
133136
def send_handle(h):
134137
self._driver.execute(Command.SWITCH_TO_WINDOW, {"handle": h})
135138

0 commit comments

Comments
 (0)