Class EventFiringWebDriver
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
IWebDriverThe 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
PageSource
Gets the source of the page last loaded by the browser.
public string PageSource { get; }
Property Value
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
Url
Gets or sets the URL the browser is currently displaying.
public string Url { get; set; }
Property Value
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
WrappedDriver
Gets the IWebDriver wrapped by this EventsFiringWebDriver instance.
public IWebDriver WrappedDriver { get; }
Property Value
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
booltrue 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
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
PinnedScriptA 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
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
ByThe 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
ByThe 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
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
WebElementEventArgsA WebElementEventArgs that contains the event data.
OnElementClicking(WebElementEventArgs)
Raises the ElementClicking event.
protected virtual void OnElementClicking(WebElementEventArgs e)
Parameters
e
WebElementEventArgsA WebElementEventArgs that contains the event data.
OnElementValueChanged(WebElementValueEventArgs)
Raises the ElementValueChanged event.
protected virtual void OnElementValueChanged(WebElementValueEventArgs e)
Parameters
e
WebElementValueEventArgsA WebElementValueEventArgs that contains the event data.
OnElementValueChanging(WebElementValueEventArgs)
Raises the ElementValueChanging event.
protected virtual void OnElementValueChanging(WebElementValueEventArgs e)
Parameters
e
WebElementValueEventArgsA WebElementValueEventArgs that contains the event data.
OnException(WebDriverExceptionEventArgs)
Raises the ExceptionThrown event.
protected virtual void OnException(WebDriverExceptionEventArgs e)
Parameters
e
WebDriverExceptionEventArgsA WebDriverExceptionEventArgs that contains the event data.
OnFindElementCompleted(FindElementEventArgs)
Raises the FindElementCompleted event.
protected virtual void OnFindElementCompleted(FindElementEventArgs e)
Parameters
e
FindElementEventArgsA FindElementEventArgs that contains the event data.
OnFindingElement(FindElementEventArgs)
Raises the FindingElement event.
protected virtual void OnFindingElement(FindElementEventArgs e)
Parameters
e
FindElementEventArgsA FindElementEventArgs that contains the event data.
OnGetShadowRootCompleted(GetShadowRootEventArgs)
Raises the OnGetShadowRootCompleted(GetShadowRootEventArgs) event.
protected virtual void OnGetShadowRootCompleted(GetShadowRootEventArgs e)
Parameters
e
GetShadowRootEventArgsA GetShadowRootEventArgs that contains the event data.
OnGettingShadowRoot(GetShadowRootEventArgs)
Raises the OnGettingShadowRoot(GetShadowRootEventArgs) event.
protected virtual void OnGettingShadowRoot(GetShadowRootEventArgs e)
Parameters
e
GetShadowRootEventArgsA GetShadowRootEventArgs that contains the event data.
OnNavigated(WebDriverNavigationEventArgs)
Raises the Navigated event.
protected virtual void OnNavigated(WebDriverNavigationEventArgs e)
Parameters
e
WebDriverNavigationEventArgsA WebDriverNavigationEventArgs that contains the event data.
OnNavigatedBack(WebDriverNavigationEventArgs)
Raises the NavigatedBack event.
protected virtual void OnNavigatedBack(WebDriverNavigationEventArgs e)
Parameters
e
WebDriverNavigationEventArgsA WebDriverNavigationEventArgs that contains the event data.
OnNavigatedForward(WebDriverNavigationEventArgs)
Raises the NavigatedForward event.
protected virtual void OnNavigatedForward(WebDriverNavigationEventArgs e)
Parameters
e
WebDriverNavigationEventArgsA WebDriverNavigationEventArgs that contains the event data.
OnNavigating(WebDriverNavigationEventArgs)
Raises the Navigating event.
protected virtual void OnNavigating(WebDriverNavigationEventArgs e)
Parameters
e
WebDriverNavigationEventArgsA WebDriverNavigationEventArgs that contains the event data.
OnNavigatingBack(WebDriverNavigationEventArgs)
Raises the NavigatingBack event.
protected virtual void OnNavigatingBack(WebDriverNavigationEventArgs e)
Parameters
e
WebDriverNavigationEventArgsA WebDriverNavigationEventArgs that contains the event data.
OnNavigatingForward(WebDriverNavigationEventArgs)
Raises the NavigatingForward event.
protected virtual void OnNavigatingForward(WebDriverNavigationEventArgs e)
Parameters
e
WebDriverNavigationEventArgsA WebDriverNavigationEventArgs that contains the event data.
OnScriptExecuted(WebDriverScriptEventArgs)
Raises the ScriptExecuted event.
protected virtual void OnScriptExecuted(WebDriverScriptEventArgs e)
Parameters
e
WebDriverScriptEventArgsA WebDriverScriptEventArgs that contains the event data.
OnScriptExecuting(WebDriverScriptEventArgs)
Raises the ScriptExecuting event.
protected virtual void OnScriptExecuting(WebDriverScriptEventArgs e)
Parameters
e
WebDriverScriptEventArgsA 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
ElementClicking
Fires before the driver clicks on an element.
public event EventHandler<WebElementEventArgs>? ElementClicking
Event Type
ElementValueChanged
Fires after the driver has changed the value of an element via Clear(), SendKeys() or Toggle().
public event EventHandler<WebElementValueEventArgs>? ElementValueChanged
Event Type
ElementValueChanging
Fires before the driver changes the value of an element via Clear(), SendKeys() or Toggle().
public event EventHandler<WebElementValueEventArgs>? ElementValueChanging
Event Type
ExceptionThrown
Fires when an exception is thrown.
public event EventHandler<WebDriverExceptionEventArgs>? ExceptionThrown
Event Type
FindElementCompleted
Fires after the driver completes finding an element.
public event EventHandler<FindElementEventArgs>? FindElementCompleted
Event Type
FindingElement
Fires before the driver starts to find an element.
public event EventHandler<FindElementEventArgs>? FindingElement
Event Type
GetShadowRootCompleted
Fires after the driver completes getting a shadow root.
public event EventHandler<GetShadowRootEventArgs>? GetShadowRootCompleted
Event Type
GettingShadowRoot
Fires before the driver starts to get a shadow root.
public event EventHandler<GetShadowRootEventArgs>? GettingShadowRoot
Event Type
Navigated
Fires after the driver completes navigation
public event EventHandler<WebDriverNavigationEventArgs>? Navigated
Event Type
NavigatedBack
Fires after the driver completes navigation back one entry in the browser history list.
public event EventHandler<WebDriverNavigationEventArgs>? NavigatedBack
Event Type
NavigatedForward
Fires after the driver completes navigation forward one entry in the browser history list.
public event EventHandler<WebDriverNavigationEventArgs>? NavigatedForward
Event Type
Navigating
Fires before the driver begins navigation.
public event EventHandler<WebDriverNavigationEventArgs>? Navigating
Event Type
NavigatingBack
Fires before the driver begins navigation back one entry in the browser history list.
public event EventHandler<WebDriverNavigationEventArgs>? NavigatingBack
Event Type
NavigatingForward
Fires before the driver begins navigation forward one entry in the browser history list.
public event EventHandler<WebDriverNavigationEventArgs>? NavigatingForward
Event Type
ScriptExecuted
Fires after a script is executed.
public event EventHandler<WebDriverScriptEventArgs>? ScriptExecuted
Event Type
ScriptExecuting
Fires before a script is executed.
public event EventHandler<WebDriverScriptEventArgs>? ScriptExecuting