Skip to content

Commit

Permalink
[py]: Additional types for element fetching methods (#10662)
Browse files Browse the repository at this point in the history
* add additional types for some `find_element?s(...)` methods

* [py]: fix unused imports in `event_firing_webdriver`
  • Loading branch information
symonk authored Jun 9, 2022
1 parent f9018c6 commit de9675b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
5 changes: 1 addition & 4 deletions py/selenium/webdriver/remote/shadowroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,9 @@ def __init__(self, session, id_):
def __eq__(self, other_shadowroot):
return self._id == other_shadowroot._id

def __hash__(self):
def __hash__(self) -> int:
return int(md5_hash(self._id.encode("utf-8")).hexdigest(), 16)

def __ne__(self, other_shadowroot):
return not self.__eq__(other_shadowroot)

def __repr__(self):
return '<{0.__module__}.{0.__name__} (session="{1}", element="{2}")>'.format(
type(self), self.session.session_id, self._id
Expand Down
5 changes: 3 additions & 2 deletions py/selenium/webdriver/remote/webelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from __future__ import annotations

import os
import typing
from base64 import b64decode, encodebytes
from hashlib import md5 as md5_hash
import pkgutil
Expand Down Expand Up @@ -396,7 +397,7 @@ def _execute(self, command, params=None):
params['id'] = self._id
return self._parent.execute(command, params)

def find_element(self, by=By.ID, value=None):
def find_element(self, by=By.ID, value=None) -> WebElement:
"""
Find an element given a By strategy and locator.
Expand All @@ -420,7 +421,7 @@ def find_element(self, by=By.ID, value=None):
return self._execute(Command.FIND_CHILD_ELEMENT,
{"using": by, "value": value})['value']

def find_elements(self, by=By.ID, value=None):
def find_elements(self, by=By.ID, value=None) -> typing.List[WebElement]:
"""
Find elements given a By strategy and locator.
Expand Down
10 changes: 5 additions & 5 deletions py/selenium/webdriver/support/event_firing_webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

import typing

from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common.by import By
Expand Down Expand Up @@ -102,10 +102,10 @@ def close(self):
def quit(self):
self._dispatch("quit", (self._driver,), "quit", ())

def find_element(self, by=By.ID, value=None):
def find_element(self, by=By.ID, value=None) -> WebElement:
return self._dispatch("find", (by, value, self._driver), "find_element", (by, value))

def find_elements(self, by=By.ID, value=None):
def find_elements(self, by=By.ID, value=None) -> typing.List[WebElement]:
return self._dispatch("find", (by, value, self._driver), "find_elements", (by, value))

def _dispatch(self, l_call, l_args, d_call, d_args):
Expand Down Expand Up @@ -188,10 +188,10 @@ def clear(self):
def send_keys(self, *value):
self._dispatch("change_value_of", (self._webelement, self._driver), "send_keys", value)

def find_element(self, by=By.ID, value=None):
def find_element(self, by=By.ID, value=None) -> WebElement:
return self._dispatch("find", (by, value, self._driver), "find_element", (by, value))

def find_elements(self, by=By.ID, value=None):
def find_elements(self, by=By.ID, value=None) -> typing.List[WebElement]:
return self._dispatch("find", (by, value, self._driver), "find_elements", (by, value))

def _dispatch(self, l_call, l_args, d_call, d_args):
Expand Down
2 changes: 1 addition & 1 deletion py/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[flake8]
exclude = .tox,docs/source/conf.py
exclude = .tox,docs/source/conf.py,*venv
ignore = E501

[tool:pytest]
Expand Down

0 comments on commit de9675b

Please sign in to comment.