Skip to content

Selenium WebDriver wrapper that adds the ability to capture DOM & browser events triggered by a live user.

License

Notifications You must be signed in to change notification settings

AbrahamSanders/Selenium.WebDriver.EventCapture

Repository files navigation

Selenium.WebDriver.EventCapture

Selenium.WebDriver.EventCapture is a WebDriver wrapper that adds the ability to capture DOM & browser events triggered by a live user.

How does it work?

Selenium.WebDriver.EventCapture extends the existing EventFiringWebDriver to support capture of DOM events through a new subclass EventCapturingWebDriver. This is made possible through a javascript event queue mechanism. The implementation was inspired by Alp's stackoverflow answer.

In a nutshell: a script is injected into the DOM which registers a global event handler that dumps event information into a queue. Then, the EventCapturingWebDriver repeatedly polls the DOM on a very short interval to pull the latest events off the queue and return them to be raised. Calling code can subscribe to these DOM events through C# event handlers:

EventCapturingWebDriver driver = new EventCapturingWebDriver(baseDriver);

driver.ElementClickCaptured += Driver_ElementClickCaptured;
driver.ElementMouseOverCaptured += Driver_ElementMouseOverCaptured;
driver.ElementKeyPressCaptured += Driver_ElementKeyPressCaptured;

driver.Navigate().GoToUrl("http://www.wikipedia.org");

Why would I want to capture DOM events from Selenium?

Selenium is mainly used for test automation, where capturing events is not necessary. However, there are some less common alternative uses for Selenium such as recording macros, filling forms, and others where Selenium is used to automate a browser being actively used by a live user. In these scenarios it is useful to be able to capture events raised by the actual browser DOM in addition to events raised by WebDriver actions.

As of now, Selenium WebDriver lacks the facility to capture events from the DOM and allow the user to subscribe to ones he/she is interested in. The built-in EventFiringWebDriver only fires events raised by the WebDriver itself rather than raised by the live DOM.

There are quite a few posts from the last few years where people are looking for this functionality: (here, here, here, here, etc...), so it is only logical to assume that there is need for it.

About

Selenium WebDriver wrapper that adds the ability to capture DOM & browser events triggered by a live user.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages