diff --git a/appium/options/common/base.py b/appium/options/common/base.py index c546c505..17bccb61 100644 --- a/appium/options/common/base.py +++ b/appium/options/common/base.py @@ -69,7 +69,7 @@ def __init__(self) -> None: # FIXME: https://github.com/SeleniumHQ/selenium/issues/10755 self._ignore_local_proxy = False - def set_capability(self: T, name: str, value: Any) -> T: + def set_capability(self: T, name: str, value: Any) -> T: # type: ignore[override] w3c_name = name if name in self.W3C_CAPABILITY_NAMES or ':' in name else f'{APPIUM_PREFIX}{name}' if value is None: if w3c_name in self._caps: diff --git a/appium/protocols/webdriver/can_find_elements.py b/appium/protocols/webdriver/can_find_elements.py index 088d9fb0..07b0b827 100644 --- a/appium/protocols/webdriver/can_find_elements.py +++ b/appium/protocols/webdriver/can_find_elements.py @@ -12,13 +12,21 @@ # See the License for the specific language governing permissions and # limitations under the License. -from typing import TYPE_CHECKING, Dict, List, Protocol, Union +from typing import TYPE_CHECKING, Dict, List, Protocol, Union, runtime_checkable if TYPE_CHECKING: from appium.webdriver.webelement import WebElement +@runtime_checkable class CanFindElements(Protocol): + """Protocol for objects that can find web elements. + + Any class implementing this protocol must provide: + - find_element(by, value): Find a single element + - find_elements(by, value): Find multiple elements + """ + def find_element(self, by: str, value: Union[str, Dict, None] = None) -> 'WebElement': ... def find_elements(self, by: str, value: Union[str, Dict, None] = None) -> List['WebElement']: ... diff --git a/appium/webdriver/webdriver.py b/appium/webdriver/webdriver.py index 323a81ea..e5459335 100644 --- a/appium/webdriver/webdriver.py +++ b/appium/webdriver/webdriver.py @@ -28,7 +28,6 @@ from appium.common.logger import logger from appium.options.common.base import AppiumOptions -from appium.protocols.webdriver.can_find_elements import CanFindElements from appium.webdriver.common.appiumby import AppiumBy from .appium_connection import AppiumConnection @@ -238,7 +237,6 @@ class WebDriver( Settings, Sms, SystemBars, - CanFindElements, ): def __init__( self, diff --git a/appium/webdriver/webelement.py b/appium/webdriver/webelement.py index f6b7faa3..3a3e8e56 100644 --- a/appium/webdriver/webelement.py +++ b/appium/webdriver/webelement.py @@ -19,16 +19,14 @@ from selenium.webdriver.remote.webelement import WebElement as SeleniumWebElement from typing_extensions import Self -from appium.protocols.webdriver.can_find_elements import CanFindElements - from .mobilecommand import MobileCommand as Command -class WebElement(SeleniumWebElement, CanFindElements): +class WebElement(SeleniumWebElement): _execute: Callable _id: str - def get_attribute(self, name: str) -> Optional[Union[str, Dict]]: + def get_attribute(self, name: str) -> Optional[Union[str, Dict]]: # type: ignore[override] """Gets the given attribute or property of the element. Override for Appium @@ -80,7 +78,7 @@ def is_displayed(self) -> bool: """ return self._execute(Command.IS_ELEMENT_DISPLAYED)['value'] - def clear(self) -> Self: + def clear(self) -> Self: # type: ignore[override] """Clears text. Override for Appium