Conversation
… 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.
KazuCocoa
reviewed
Sep 21, 2026
|
|
||
| from typing import TYPE_CHECKING, Protocol, runtime_checkable | ||
|
|
||
| from selenium.webdriver.common.by import By |
Member
There was a problem hiding this comment.
Move to under if TYPE_CHECKING?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In Selenium's
WebElement.find_elementandfind_elements, the locator strategybyparameter defaults toBy.ID(by: str = By.ID).While PR #1298 preserved the default
By.IDlocator strategy forWebDriver,WebElementand theCanFindElementsprotocol were omitted and continued to requirebyin their type hints (by: str). This causes static type checkers (such asmypy) to reject valid calls likeelement.find_element(value='child')orelement.find_elements(value='items')with a missing positional argument error.This PR adds the default
By.IDlocator strategy toWebElementandCanFindElements, completing the consistency established in #1298 across the client.Changes
by: str = By.IDdefault tofind_elementandfind_elementsstubs inappium/webdriver/webelement.py(withfrom selenium.webdriver.common.by import Byunderif TYPE_CHECKING:).by: str = By.IDdefault toappium/protocols/webdriver/can_find_elements.py.test/unit/webdriver/webelement_test.pyverifying omittedbydispatch and protocol conformance.