diff --git a/dotnet/src/webdriver/Interactions/PointerInputDevice.cs b/dotnet/src/webdriver/Interactions/PointerInputDevice.cs index 5979dbaa00f99..b8d48b25f3251 100644 --- a/dotnet/src/webdriver/Interactions/PointerInputDevice.cs +++ b/dotnet/src/webdriver/Interactions/PointerInputDevice.cs @@ -17,10 +17,10 @@ // under the License. // +using OpenQA.Selenium.Internal; using System; using System.Collections.Generic; using System.Globalization; -using OpenQA.Selenium.Internal; #nullable enable @@ -582,17 +582,23 @@ public override string ToString() private Dictionary ConvertElement() { - if (this.target is IWebDriverObjectReference element) + IWebDriverObjectReference? elementReference = this.target as IWebDriverObjectReference; + if (elementReference == null) { - return element.ToDictionary(); + IWrapsElement? elementWrapper = this.target as IWrapsElement; + if (elementWrapper != null) + { + elementReference = elementWrapper.WrappedElement as IWebDriverObjectReference; + } } - if (this.target is IWrapsElement { WrappedElement: IWebDriverObjectReference wrappedElement }) + if (elementReference == null) { - return wrappedElement.ToDictionary(); + throw new ArgumentException("Target element cannot be converted to IWebElementReference"); } - throw new ArgumentException("Target element cannot be converted to IWebElementReference"); + Dictionary elementDictionary = elementReference.ToDictionary(); + return elementDictionary; } } } diff --git a/dotnet/src/webdriver/Interactions/WheelInputDevice.cs b/dotnet/src/webdriver/Interactions/WheelInputDevice.cs index 39ac416121b78..c3e049a290ee0 100644 --- a/dotnet/src/webdriver/Interactions/WheelInputDevice.cs +++ b/dotnet/src/webdriver/Interactions/WheelInputDevice.cs @@ -17,9 +17,9 @@ // under the License. // +using OpenQA.Selenium.Internal; using System; using System.Collections.Generic; -using OpenQA.Selenium.Internal; #nullable enable @@ -203,17 +203,23 @@ public override Dictionary ToDictionary() private Dictionary ConvertElement() { - if (this.target is IWebDriverObjectReference element) + IWebDriverObjectReference? elementReference = this.target as IWebDriverObjectReference; + if (elementReference == null) { - return element.ToDictionary(); + IWrapsElement? elementWrapper = this.target as IWrapsElement; + if (elementWrapper != null) + { + elementReference = elementWrapper.WrappedElement as IWebDriverObjectReference; + } } - if (this.target is IWrapsElement { WrappedElement: IWebDriverObjectReference wrappedElement }) + if (elementReference == null) { - return wrappedElement.ToDictionary(); + throw new ArgumentException("Target element cannot be converted to IWebElementReference"); } - throw new ArgumentException("Target element cannot be converted to IWebElementReference"); + Dictionary elementDictionary = elementReference.ToDictionary(); + return elementDictionary; } } }