Skip to content

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

Merged
KazuCocoa merged 1 commit into
appium:masterfrom
Dor-bl:fix/webelement-default-locator-types
Oct 24, 2026
Merged

KazuCocoa merged 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.

Comment thread appium/protocols/webdriver/can_find_elements.py Outdated
… 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.
@Dor-bl
Dor-bl force-pushed the fix/webelement-default-locator-types branch from 9991ebc to 8c89435 Compare October 24, 2026 15:18
@KazuCocoa
KazuCocoa merged commit efb4085 into appium:master Oct 24, 2026
13 checks passed
@Dor-bl
Dor-bl deleted the fix/webelement-default-locator-types branch October 24, 2026 19:45
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