Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[py]: Additional types for element fetching methods #10662

Merged
merged 4 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add additional types for some find_element?s(...) methods
  • Loading branch information
symonk committed May 17, 2022
commit 3aa95737365eb596b0307d404de07a0de1aeb5e0
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):
symonk marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -751,7 +752,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 @@ -775,7 +776,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
11 changes: 5 additions & 6 deletions py/selenium/webdriver/support/event_firing_webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.


import typing
import warnings

from selenium.common.exceptions import WebDriverException
Expand Down Expand Up @@ -104,10 +103,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 find_element_by_id(self, id_):
Expand Down Expand Up @@ -254,10 +253,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 find_element_by_id(self, id_):
Expand Down