Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 13 additions & 5 deletions py/selenium/webdriver/remote/shadowroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@
# under the License.

from hashlib import md5 as md5_hash
from typing import TYPE_CHECKING, Union

from ..common.by import By
if TYPE_CHECKING:
from selenium.webdriver.support.relative_locator import RelativeBy

from ..common.by import By, ByType
from .command import Command


Expand All @@ -43,7 +47,7 @@ def __repr__(self) -> str:
def id(self) -> str:
return self._id

def find_element(self, by: str = By.ID, value: str = None):
def find_element(self, by: "Union[ByType, RelativeBy]" = By.ID, value: str = None):
"""Find an element inside a shadow root given a By strategy and
locator.

Expand Down Expand Up @@ -80,9 +84,11 @@ def find_element(self, by: str = By.ID, value: str = None):
by = By.CSS_SELECTOR
value = f'[name="{value}"]'

return self._execute(Command.FIND_ELEMENT_FROM_SHADOW_ROOT, {"using": by, "value": value})["value"]
return self._execute(
Command.FIND_ELEMENT_FROM_SHADOW_ROOT, {"using": by, "value": value}
)["value"]

def find_elements(self, by: str = By.ID, value: str = None):
def find_elements(self, by: "Union[ByType, RelativeBy]" = By.ID, value: str = None):
"""Find elements inside a shadow root given a By strategy and locator.

Parameters:
Expand Down Expand Up @@ -118,7 +124,9 @@ def find_elements(self, by: str = By.ID, value: str = None):
by = By.CSS_SELECTOR
value = f'[name="{value}"]'

return self._execute(Command.FIND_ELEMENTS_FROM_SHADOW_ROOT, {"using": by, "value": value})["value"]
return self._execute(
Command.FIND_ELEMENTS_FROM_SHADOW_ROOT, {"using": by, "value": value}
)["value"]

# Private Methods
def _execute(self, command, params=None):
Expand Down
Loading