diff --git a/dotnet/src/support/Events/EventFiringWebDriver.cs b/dotnet/src/support/Events/EventFiringWebDriver.cs index abc7643757e42..46cf4aaf2fbcd 100644 --- a/dotnet/src/support/Events/EventFiringWebDriver.cs +++ b/dotnet/src/support/Events/EventFiringWebDriver.cs @@ -1419,6 +1419,20 @@ public void Submit() } } + public override bool Equals(object obj) + { + if (!(obj is IWebElement)) + return false; + + IWebElement other = (IWebElement)obj; + if(other is IWrapsElement wrapper) + { + other = ((IWrapsElement)wrapper).WrappedElement; + } + + return underlyingElement.Equals(other); + } + /// /// Click this element. If this causes a new page to load, this method will block until /// the page has loaded. At this point, you should discard all references to this element diff --git a/dotnet/test/support/Events/EventFiringWebDriverTest.cs b/dotnet/test/support/Events/EventFiringWebDriverTest.cs index 54a9be0c9d93b..b9f6bbbefe865 100644 --- a/dotnet/test/support/Events/EventFiringWebDriverTest.cs +++ b/dotnet/test/support/Events/EventFiringWebDriverTest.cs @@ -106,6 +106,18 @@ public void ShouldFireValueChangedEvent() Assert.AreEqual(expectedLog, log.ToString()); } + [Test] + public void ElementsCanEqual() + { + mockDriver.Setup(_ => _.FindElement(It.Is(x => x.Equals(By.Id("foo"))))).Returns(mockElement.Object); + + EventFiringWebDriver firingDriver = new EventFiringWebDriver(mockDriver.Object); + var element1 = firingDriver.FindElement(By.Id("foo")); + var element2 = firingDriver.FindElement(By.Id("foo")); + + Assert.AreEqual(element1, element2); + } + [Test] public void ShouldFireFindByEvent() {