Table of Contents

Class EventFiringWebDriver

Namespace
OpenQA.Selenium.Support.Events
Assembly
WebDriver.Support.dll

A wrapper around an arbitrary WebDriver instance which supports registering for events, e.g. for logging purposes.

public class EventFiringWebDriver : IWebDriver, ISearchContext, IDisposable, IJavaScriptExecutor, ITakesScreenshot, IWrapsDriver
Inheritance
EventFiringWebDriver
Implements
Inherited Members
Extension Methods

Constructors

EventFiringWebDriver(IWebDriver)

Initializes a new instance of the EventFiringWebDriver class.

public EventFiringWebDriver(IWebDriver parentDriver)

Parameters

parentDriver IWebDriver

The driver to register events for.

Exceptions

ArgumentNullException

If parentDriver is null.

Properties

CurrentWindowHandle

Gets the current window handle, which is an opaque handle to this window that uniquely identifies it within this driver instance.

public string CurrentWindowHandle { get; }

Property Value

string

PageSource

Gets the source of the page last loaded by the browser.

public string PageSource { get; }

Property Value

string

Remarks

If the page has been modified after loading (for example, by JavaScript) there is no guarantee that the returned text is that of the modified page. Please consult the documentation of the particular driver being used to determine whether the returned text reflects the current state of the page or the text last sent by the web server. The page source returned is a representation of the underlying DOM: do not expect it to be formatted or escaped in the same way as the response sent from the web server.

Title

Gets the title of the current browser window.

public string Title { get; }

Property Value

string

Url

Gets or sets the URL the browser is currently displaying.

public string Url { get; set; }

Property Value

string

Remarks

Setting the Url property will load a new web page in the current browser window. This is done using an HTTP GET operation, and the method will block until the load is complete. This will follow redirects issued either by the server or as a meta-redirect from within the returned HTML. Should a meta-redirect "rest" for any duration of time, it is best to wait until this timeout is over, since should the underlying page change while your test is executing the results of future calls against this interface will be against the freshly loaded page.

See Also

WindowHandles

Gets the window handles of open browser windows.

public ReadOnlyCollection<string> WindowHandles { get; }

Property Value

ReadOnlyCollection<string>

WrappedDriver

Gets the IWebDriver wrapped by this EventsFiringWebDriver instance.

public IWebDriver WrappedDriver { get; }

Property Value

IWebDriver

Methods

Close()

Close the current window, quitting the browser if it is the last window currently open.

public void Close()

Dispose()

Frees all managed and unmanaged resources used by this instance.

public void Dispose()

Dispose(bool)

Frees all managed and, optionally, unmanaged resources used by this instance.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

true to dispose of only managed resources; false to dispose of managed and unmanaged resources.

ExecuteAsyncScript(string, params object?[])

Executes JavaScript asynchronously in the context of the currently selected frame or window.

public object ExecuteAsyncScript(string script, params object?[] args)

Parameters

script string

The JavaScript code to execute.

args object[]

The arguments to the script.

Returns

object

The value returned by the script.

ExecuteScript(PinnedScript, params object?[])

Executes JavaScript in the context of the currently selected frame or window.

public object ExecuteScript(PinnedScript script, params object?[] args)

Parameters

script PinnedScript

A PinnedScript object containing the code to execute.

args object[]

The arguments to the script.

Returns

object

The value returned by the script.

Remarks

The ExecuteScript method executes JavaScript in the context of the currently selected frame or window. This means that "document" will refer to the current document. If the script has a return value, then the following steps will be taken:

  • For an HTML element, this method returns a IWebElement
  • For a number, a long is returned
  • For a boolean, a bool is returned
  • For all other cases a string is returned.
  • For an array,we check the first element, and attempt to return a List<T> of that type, following the rules above. Nested lists are not supported.
  • If the value is null or there is no return value, null is returned.

Arguments must be a number (which will be converted to a long), a bool, a string or a IWebElement, or a IWrapsElement. An exception will be thrown if the arguments do not meet these criteria. The arguments will be made available to the JavaScript via the "arguments" magic variable, as if the function were called via "Function.apply"

Exceptions

ArgumentNullException

If script is null.

ExecuteScript(string, params object?[])

Executes JavaScript in the context of the currently selected frame or window.

public object ExecuteScript(string script, params object?[] args)

Parameters

script string

The JavaScript code to execute.

args object[]

The arguments to the script.

Returns

object

The value returned by the script.

Remarks

The ExecuteScript method executes JavaScript in the context of the currently selected frame or window. This means that "document" will refer to the current document. If the script has a return value, then the following steps will be taken:

  • For an HTML element, this method returns a IWebElement
  • For a number, a long is returned
  • For a boolean, a bool is returned
  • For all other cases a string is returned.
  • For an array,we check the first element, and attempt to return a List<T> of that type, following the rules above. Nested lists are not supported.
  • If the value is null or there is no return value, null is returned.

Arguments must be a number (which will be converted to a long), a bool, a string or a IWebElement, or a IWrapsElement. An exception will be thrown if the arguments do not meet these criteria. The arguments will be made available to the JavaScript via the "arguments" magic variable, as if the function were called via "Function.apply"

FindElement(By)

Find the first IWebElement using the given method.

public IWebElement FindElement(By by)

Parameters

by By

The locating mechanism to use.

Returns

IWebElement

The first matching IWebElement on the current context.

Exceptions

NoSuchElementException

If no element matches the criteria.

FindElements(By)

Find all IWebElements within the current context using the given mechanism.

public ReadOnlyCollection<IWebElement> FindElements(By by)

Parameters

by By

The locating mechanism to use.

Returns

ReadOnlyCollection<IWebElement>

A ReadOnlyCollection<T> of all WebElements matching the current criteria, or an empty list if nothing matches.

GetScreenshot()

Gets a Screenshot object representing the image of the page on the screen.

public Screenshot GetScreenshot()

Returns

Screenshot

A Screenshot object containing the image.

Manage()

Instructs the driver to change its settings.

public IOptions Manage()

Returns

IOptions

An IOptions object allowing the user to change the settings of the driver.

Navigate()

Instructs the driver to navigate the browser to another location.

public INavigation Navigate()

Returns

INavigation

An INavigation object allowing the user to access the browser's history and to navigate to a given URL.

OnElementClicked(WebElementEventArgs)

Raises the ElementClicked event.

protected virtual void OnElementClicked(WebElementEventArgs e)

Parameters

e WebElementEventArgs

A WebElementEventArgs that contains the event data.

OnElementClicking(WebElementEventArgs)

Raises the ElementClicking event.

protected virtual void OnElementClicking(WebElementEventArgs e)

Parameters

e WebElementEventArgs

A WebElementEventArgs that contains the event data.

OnElementValueChanged(WebElementValueEventArgs)

Raises the ElementValueChanged event.

protected virtual void OnElementValueChanged(WebElementValueEventArgs e)

Parameters

e WebElementValueEventArgs

A WebElementValueEventArgs that contains the event data.

OnElementValueChanging(WebElementValueEventArgs)

Raises the ElementValueChanging event.

protected virtual void OnElementValueChanging(WebElementValueEventArgs e)

Parameters

e WebElementValueEventArgs

A WebElementValueEventArgs that contains the event data.

OnException(WebDriverExceptionEventArgs)

Raises the ExceptionThrown event.

protected virtual void OnException(WebDriverExceptionEventArgs e)

Parameters

e WebDriverExceptionEventArgs

A WebDriverExceptionEventArgs that contains the event data.

OnFindElementCompleted(FindElementEventArgs)

Raises the FindElementCompleted event.

protected virtual void OnFindElementCompleted(FindElementEventArgs e)

Parameters

e FindElementEventArgs

A FindElementEventArgs that contains the event data.

OnFindingElement(FindElementEventArgs)

Raises the FindingElement event.

protected virtual void OnFindingElement(FindElementEventArgs e)

Parameters

e FindElementEventArgs

A FindElementEventArgs that contains the event data.

OnGetShadowRootCompleted(GetShadowRootEventArgs)

protected virtual void OnGetShadowRootCompleted(GetShadowRootEventArgs e)

Parameters

e GetShadowRootEventArgs

A GetShadowRootEventArgs that contains the event data.

OnGettingShadowRoot(GetShadowRootEventArgs)

protected virtual void OnGettingShadowRoot(GetShadowRootEventArgs e)

Parameters

e GetShadowRootEventArgs

A GetShadowRootEventArgs that contains the event data.

OnNavigated(WebDriverNavigationEventArgs)

Raises the Navigated event.

protected virtual void OnNavigated(WebDriverNavigationEventArgs e)

Parameters

e WebDriverNavigationEventArgs

A WebDriverNavigationEventArgs that contains the event data.

OnNavigatedBack(WebDriverNavigationEventArgs)

Raises the NavigatedBack event.

protected virtual void OnNavigatedBack(WebDriverNavigationEventArgs e)

Parameters

e WebDriverNavigationEventArgs

A WebDriverNavigationEventArgs that contains the event data.

OnNavigatedForward(WebDriverNavigationEventArgs)

Raises the NavigatedForward event.

protected virtual void OnNavigatedForward(WebDriverNavigationEventArgs e)

Parameters

e WebDriverNavigationEventArgs

A WebDriverNavigationEventArgs that contains the event data.

OnNavigating(WebDriverNavigationEventArgs)

Raises the Navigating event.

protected virtual void OnNavigating(WebDriverNavigationEventArgs e)

Parameters

e WebDriverNavigationEventArgs

A WebDriverNavigationEventArgs that contains the event data.

OnNavigatingBack(WebDriverNavigationEventArgs)

Raises the NavigatingBack event.

protected virtual void OnNavigatingBack(WebDriverNavigationEventArgs e)

Parameters

e WebDriverNavigationEventArgs

A WebDriverNavigationEventArgs that contains the event data.

OnNavigatingForward(WebDriverNavigationEventArgs)

Raises the NavigatingForward event.

protected virtual void OnNavigatingForward(WebDriverNavigationEventArgs e)

Parameters

e WebDriverNavigationEventArgs

A WebDriverNavigationEventArgs that contains the event data.

OnScriptExecuted(WebDriverScriptEventArgs)

Raises the ScriptExecuted event.

protected virtual void OnScriptExecuted(WebDriverScriptEventArgs e)

Parameters

e WebDriverScriptEventArgs

A WebDriverScriptEventArgs that contains the event data.

OnScriptExecuting(WebDriverScriptEventArgs)

Raises the ScriptExecuting event.

protected virtual void OnScriptExecuting(WebDriverScriptEventArgs e)

Parameters

e WebDriverScriptEventArgs

A WebDriverScriptEventArgs that contains the event data.

Quit()

Quits this driver, closing every associated window.

public void Quit()

SwitchTo()

Instructs the driver to send future commands to a different frame or window.

public ITargetLocator SwitchTo()

Returns

ITargetLocator

An ITargetLocator object which can be used to select a frame or window.

Events

ElementClicked

Fires after the driver has clicked on an element.

public event EventHandler<WebElementEventArgs>? ElementClicked

Event Type

EventHandler<WebElementEventArgs>

ElementClicking

Fires before the driver clicks on an element.

public event EventHandler<WebElementEventArgs>? ElementClicking

Event Type

EventHandler<WebElementEventArgs>

ElementValueChanged

Fires after the driver has changed the value of an element via Clear(), SendKeys() or Toggle().

public event EventHandler<WebElementValueEventArgs>? ElementValueChanged

Event Type

EventHandler<WebElementValueEventArgs>

ElementValueChanging

Fires before the driver changes the value of an element via Clear(), SendKeys() or Toggle().

public event EventHandler<WebElementValueEventArgs>? ElementValueChanging

Event Type

EventHandler<WebElementValueEventArgs>

ExceptionThrown

Fires when an exception is thrown.

public event EventHandler<WebDriverExceptionEventArgs>? ExceptionThrown

Event Type

EventHandler<WebDriverExceptionEventArgs>

FindElementCompleted

Fires after the driver completes finding an element.

public event EventHandler<FindElementEventArgs>? FindElementCompleted

Event Type

EventHandler<FindElementEventArgs>

FindingElement

Fires before the driver starts to find an element.

public event EventHandler<FindElementEventArgs>? FindingElement

Event Type

EventHandler<FindElementEventArgs>

GetShadowRootCompleted

Fires after the driver completes getting a shadow root.

public event EventHandler<GetShadowRootEventArgs>? GetShadowRootCompleted

Event Type

EventHandler<GetShadowRootEventArgs>

GettingShadowRoot

Fires before the driver starts to get a shadow root.

public event EventHandler<GetShadowRootEventArgs>? GettingShadowRoot

Event Type

EventHandler<GetShadowRootEventArgs>

Navigated

Fires after the driver completes navigation

public event EventHandler<WebDriverNavigationEventArgs>? Navigated

Event Type

EventHandler<WebDriverNavigationEventArgs>

NavigatedBack

Fires after the driver completes navigation back one entry in the browser history list.

public event EventHandler<WebDriverNavigationEventArgs>? NavigatedBack

Event Type

EventHandler<WebDriverNavigationEventArgs>

NavigatedForward

Fires after the driver completes navigation forward one entry in the browser history list.

public event EventHandler<WebDriverNavigationEventArgs>? NavigatedForward

Event Type

EventHandler<WebDriverNavigationEventArgs>

Navigating

Fires before the driver begins navigation.

public event EventHandler<WebDriverNavigationEventArgs>? Navigating

Event Type

EventHandler<WebDriverNavigationEventArgs>

NavigatingBack

Fires before the driver begins navigation back one entry in the browser history list.

public event EventHandler<WebDriverNavigationEventArgs>? NavigatingBack

Event Type

EventHandler<WebDriverNavigationEventArgs>

NavigatingForward

Fires before the driver begins navigation forward one entry in the browser history list.

public event EventHandler<WebDriverNavigationEventArgs>? NavigatingForward

Event Type

EventHandler<WebDriverNavigationEventArgs>

ScriptExecuted

Fires after a script is executed.

public event EventHandler<WebDriverScriptEventArgs>? ScriptExecuted

Event Type

EventHandler<WebDriverScriptEventArgs>

ScriptExecuting

Fires before a script is executed.

public event EventHandler<WebDriverScriptEventArgs>? ScriptExecuting

Event Type

EventHandler<WebDriverScriptEventArgs>