Skip to content

Conversation

@ShauryaDusht
Copy link
Contributor

@ShauryaDusht ShauryaDusht commented Jun 8, 2025

User description

🔗 Related Issues

Closes #14881

💥 What does this PR do?

Adds missing RelativeBy type annotation support to:

  • find_element and find_elements
  • expected_conditions.py (conditions now support RelativeBy locators)

Also adds unit tests to validate these changes.

🔧 Implementation Notes

  • Updated type hints from Tuple[str, str] to Union[Tuple[ByType, str], Tuple[RelativeBy, None]] where needed.

💡 Additional Considerations

N/A

🔄 Types of changes

  • Cleanup (formatting, renaming)
  • Tests coverage

Files Changed/Added

  • selenium/webdriver/remote/shadowroot.py
  • selenium/webdriver/remote/webdriver.py
  • selenium/webdriver/remote/webelement.py
  • selenium/webdriver/support/expected_conditions.py
  • test/unit/selenium/webdriver/support/test_expected_conditions_relative_by.py
  • test/unit/selenium/webdriver/test_relative_by_annotations.py

PR Type

Bug fix, Enhancement, Tests


Description

  • Add RelativeBy support to find_element and find_elements methods

    • Update type annotations in WebDriver, WebElement, and ShadowRoot
  • Update expected_conditions to accept RelativeBy locators

    • Refactor type hints for locator arguments in EC functions
  • Add unit tests for RelativeBy type annotation support

    • Tests for WebDriver, WebElement, ShadowRoot, and expected_conditions

Changes walkthrough 📝

Relevant files
Bug fix
shadowroot.py
Add RelativeBy support to ShadowRoot element search methods

py/selenium/webdriver/remote/shadowroot.py

  • Update type annotations for find_element and find_elements to accept
    RelativeBy
  • Add TYPE_CHECKING import for RelativeBy
  • Import ByType for improved type hints
  • +6/-3     
    webdriver.py
    Add RelativeBy support to WebDriver element search methods

    py/selenium/webdriver/remote/webdriver.py

  • Update type annotations for find_element and find_elements to accept
    RelativeBy
  • Add TYPE_CHECKING import for RelativeBy
  • Import ByType for improved type hints
  • Minor cleanup of unused imports
  • +8/-11   
    webelement.py
    Add RelativeBy support to WebElement search methods           

    py/selenium/webdriver/remote/webelement.py

  • Update type annotations for find_element and find_elements to accept
    RelativeBy
  • Add TYPE_CHECKING import for RelativeBy
  • Import ByType for improved type hints
  • +8/-3     
    Enhancement
    expected_conditions.py
    Add RelativeBy support to expected_conditions locator arguments

    py/selenium/webdriver/support/expected_conditions.py

  • Refactor locator type hints to accept RelativeBy
  • Introduce LocatorType alias for union of locator types
  • Update all relevant expected_conditions functions to use new type
    hints
  • +16/-12 
    Tests
    test_expected_conditions_relative_by.py
    Add tests for RelativeBy support in expected_conditions   

    py/test/unit/selenium/webdriver/support/test_expected_conditions_relative_by.py

  • Add unit tests to verify expected_conditions accept RelativeBy
    locators
  • Test multiple EC functions with RelativeBy
  • +57/-0   
    test_relative_by_annotations.py
    Add tests for RelativeBy support in element search methods

    py/test/unit/selenium/webdriver/test_relative_by_annotations.py

  • Add unit tests to verify find_element and find_elements accept
    RelativeBy
  • Test WebDriver, WebElement, and ShadowRoot with RelativeBy
  • +65/-0   

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • @selenium-ci selenium-ci added C-py Python Bindings B-support Issue or PR related to support classes labels Jun 8, 2025
    @qodo-merge-pro
    Copy link
    Contributor

    qodo-merge-pro bot commented Jun 8, 2025

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Unused Import

    The import for Permissions was removed but the permissions property and its docstring still exist in the code. This could lead to confusion or errors when trying to use this property.

        """
        pass
    
    def start_session(self, capabilities: dict) -> None:
        """Creates a new session with the desired capabilities.
    
        Parameters:
        -----------
        capabilities : dict
            - A capabilities dict to start the session with.

    @selenium-ci
    Copy link
    Member

    Thank you, @ShauryaDusht for this code suggestion.

    The support packages contain example code that many users find helpful, but they do not necessarily represent
    the best practices for using Selenium, and the Selenium team is not currently merging changes to them.

    We actively encourage people to add the wrapper and helper code that makes sense for them to their own frameworks.
    If you have any questions, please contact us

    @selenium-ci selenium-ci closed this Jun 8, 2025
    @qodo-merge-pro
    Copy link
    Contributor

    qodo-merge-pro bot commented Jun 8, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Fix property decorator indentation

    Fix the indentation of the @property decorator for the permissions method. The
    decorator is currently indented with one space more than it should be, which can
    cause Python syntax errors.

    py/selenium/webdriver/remote/webdriver.py [1343-1352]

     @property
     def permissions(self):
    -   """Returns a permissions module object for BiDi permissions commands.
    -   Returns:
    -   --------
    -   Permissions: an object containing access to BiDi permissions commands.
    -   Examples:
    -   ---------
    -   >>> from selenium.webdriver.common.bidi.permissions import PermissionDescriptor, PermissionState
    -   >>> descriptor = PermissionDescriptor("geolocation")
    +    """Returns a permissions module object for BiDi permissions commands.
    +    Returns:
    +    --------
    +    Permissions: an object containing access to BiDi permissions commands.
    +    Examples:
    +    ---------
    +    >>> from selenium.webdriver.common.bidi.permissions import PermissionDescriptor, PermissionState
    +    >>> descriptor = PermissionDescriptor("geolocation")
    • Apply / Chat
    Suggestion importance[1-10]: 8

    __

    Why: The suggestion correctly identifies a Python indentation error where the @property decorator has 5 spaces instead of the standard 4 spaces, which would cause a syntax error.

    Medium
    • More

    @cgoldberg
    Copy link
    Member

    @ShauryaDusht please stop submitting duplicate PR's. I'm leaving them all closed because I have no idea what you are actually trying to submit.

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

    Labels

    B-support Issue or PR related to support classes C-py Python Bindings Review effort 2/5

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    [🐛 Bug]: Missing support for RelativeBy in annotations

    3 participants