-
Notifications
You must be signed in to change notification settings - Fork 569
Open
Description
Mypy errors on the fact that appium.webdriver.WebDriver.find_element
isn't overridden but indeed returns a different WebElement
.
Reproducible Code
# no need to actually run this code, just send it through MyPy to see the error.
from appium.webdriver.common.appiumby import AppiumBy
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from appium.webdriver import Remote
from appium.webdriver.webelement import WebElement
def find_element(driver: Remote) -> WebElement:
# should get a mypy error on next line
return driver.find_element(AppiumBy.ACCESSIBILITY_ID, "demo button")
def find_elements(driver: Remote) -> WebElement:
# should get a mypy error on next line
return driver.find_elements(AppiumBy.ACCESSIBILITY_ID, "demo confetti")
mypy output:
mypy .
screenpy_appium/target.py:89: error: Incompatible return value type (got "selenium.webdriver.remote.webelement.WebElement", expected "appium.webdriver.webelement.WebElement") [return-value]
screenpy_appium/target.py:98: error: Incompatible return value type (got "list[selenium.webdriver.remote.webelement.WebElement]", expected "list[appium.webdriver.webelement.WebElement]") [return-value]
Found 2 errors in 1 file (checked 35 source files)
Solution
Annotations need to be added to appium.webdriver.WebDriver
class WebDriver(
webdriver.Remote,
...
):
if TYPE_CHECKING:
def find_element(self, by=By.ID, value: Optional[str] = None) -> MobileWebElement:
...
def find_elements(self, by=By.ID, value: Optional[str] = None) -> list[MobileWebElement]:
...
Metadata
Metadata
Assignees
Labels
No labels