Skip to content

fix(webelement): preserve default locator strategy in webelement type hints - #1309

Open
Dor-bl wants to merge 1 commit into
appium:masterfrom
Dor-bl:fix/webelement-default-locator-types
Open

Dor-bl wants to merge 1 commit into
appium:masterfrom
Dor-bl:fix/webelement-default-locator-types

Conversation

@Dor-bl

@Dor-bl Dor-bl commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Summary

In Selenium's WebElement.find_element and find_elements, the locator strategy by parameter defaults to By.ID (by: str = By.ID).

While PR #1298 preserved the default By.ID locator strategy for WebDriver, WebElement and the CanFindElements protocol were omitted and continued to require by in their type hints (by: str). This causes static type checkers (such as mypy) to reject valid calls like element.find_element(value='child') or element.find_elements(value='items') with a missing positional argument error.

This PR adds the default By.ID locator strategy to WebElement and CanFindElements, completing the consistency established in #1298 across the client.

Changes

  • Added by: str = By.ID default to find_element and find_elements stubs in appium/webdriver/webelement.py (with from selenium.webdriver.common.by import By under if TYPE_CHECKING:).
  • Added by: str = By.ID default to appium/protocols/webdriver/can_find_elements.py.
  • Added unit tests in test/unit/webdriver/webelement_test.py verifying omitted by dispatch and protocol conformance.

… hints

The type-only find_element and find_elements declarations in WebElement and CanFindElements required by, although their inherited Selenium implementations default it to By.ID. This makes static type checkers reject valid calls such as element.find_element(value='child') with a missing-argument error.

Add the inherited default locator strategy (by: str = By.ID) to WebElement and CanFindElements, matching WebDriver. Add unit tests covering omitted locator strategy dispatch and protocol conformance.

from typing import TYPE_CHECKING, Protocol, runtime_checkable

from selenium.webdriver.common.by import By

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to under if TYPE_CHECKING?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants