[dotnet] Unwrap element wrapper recursively by RenderMichael · Pull Request #15362 · SeleniumHQ/selenium

User description

Description

In many places, we only unwrap IWrapsElement once. This, however, has led to user issues.

This PR fixes that in a pain point from a user report. However, we should audit our usage of IWrapsElement and make sure this problem does not exist elsewhere.

There's also a lot of code duplication (or code that should be duplicated, but is implemented differently). We should centralize the element unwrapping logic.
 

Motivation and Context

Fixes #14513

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

PR Type

Bug fix, Tests


Description

  • Fixed recursive unwrapping of IWrapsElement to handle nested wrappers.

  • Added error handling for self-referencing element wrappers.

  • Introduced new tests to validate double-wrapped element handling.

  • Added WebElementWrapper class for testing wrapped elements.


Changes walkthrough 📝

Relevant files
Bug fix
PointerInputDevice.cs
Enhance `ConvertElement` to handle nested wrappers             

dotnet/src/webdriver/Interactions/PointerInputDevice.cs

  • Updated ConvertElement to recursively unwrap IWrapsElement.
  • Added error handling for self-referencing wrappers.
  • Improved exception message for invalid element conversion.
  • +9/-2     
    WheelInputDevice.cs
    Enhance `ConvertElement` to handle nested wrappers             

    dotnet/src/webdriver/Interactions/WheelInputDevice.cs

  • Updated ConvertElement to recursively unwrap IWrapsElement.
  • Added error handling for self-referencing wrappers.
  • Improved exception message for invalid element conversion.
  • +8/-2     
    Tests
    BasicMouseInterfaceTest.cs
    Add test for double-wrapped elements in mouse actions       

    dotnet/test/common/Interactions/BasicMouseInterfaceTest.cs

  • Added test for handling double-wrapped elements in mouse actions.
  • Verified MoveToElement and Click functionality with wrapped elements.
  • +18/-0   
    BasicWheelInterfaceTest.cs
    Add test for double-wrapped elements in wheel actions       

    dotnet/test/common/Interactions/BasicWheelInterfaceTest.cs

  • Added test for handling double-wrapped elements in wheel actions.
  • Verified ScrollToElement functionality with wrapped elements.
  • +17/-0   
    WebElementWrapper.cs
    Introduce `WebElementWrapper` for testing                               

    dotnet/test/common/WebElementWrapper.cs

  • Added WebElementWrapper class implementing IWebElement and
    IWrapsElement.
  • Used for testing wrapped element scenarios.
  • +105/-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.