Skip to content

WebEvents

Avrigeanu Laurian edited this page Sep 5, 2022 · 13 revisions

The WebEvents class contains two types of actions, activities or methods, depending on your background:

  • JavaScript.
  • Selenium.

The WebEvents class is specialized only from Web Interactions and nothing else (as the name implies).

To be able to use this class, you will need to know how to write your own XPaths, however, I recommend you as a helper tool SelectorsHub Chrome extension as training wheels, there is also this tutorial you can find here that can teach you everything you need to know about XPaths: https://www.w3schools.com/xml/xpath_intro.asp.

ActionJs

This subclass contains all of the methods that interact with the browser in JavaScript .

They are very agile and powerful and I recommend you use them only as a last resort.

Don't use a chainsaw to cut salmon.

Hover (IWebElement)

This method will trigger a JavaScript hover event on the element it finds.

Mandatory Parameters Optional Parameters
ChromeDriver chromeDriver int retries (default:15)
string xPath int retryInterval (default 1)

Example:

WebEvents.ActionJs.Hover(chromeDriver, "//*[@id='wiki-wrapper']/div[1]/h1");

WaitForeverElementVanish (IWebElement)

This method will search for an element in a web page until it can no longer find it, forever.

Mandatory Parameters Optional Parameters
ChromeDriver chromeDriver int retryInterval (default 1)
string xPath

Example:

WebEvents.ActionJs.WaitForeverElementVanish(chromeDriver, "//*[@id='wiki-wrapper']/div[1]/h1");

WaitElementVanish (IWebElement)

This method will search for an element in a web page until it can no longer find it.

Mandatory Parameters Optional Parameters
ChromeDriver chromeDriver int retries (default 60)
string xPath int retryInterval (default 1)

Example:

WebEvents.ActionJs.WaitElementVanish(chromeDriver, "//*[@id='wiki-wrapper']/div[1]/h1");

GetText (String)

This method will search for either the text or the value of an element and return it.

Mandatory Parameters Optional Parameters
ChromeDriver chromeDriver int retries (default 15)
string xPath int retryInterval (default 1)

Example:

var textValue = WebEvents.ActionJs.GetText(chromeDriver, "//*[@id='wiki-wrapper']/div[1]/h1");

SetValue (IWebElement)

This method will set the value of an element.

Mandatory Parameters Optional Parameters
ChromeDriver chromeDriver int retries (default 15)
string xPath int retryInterval (default 1)
string text

Example:

WebEvents.ActionJs.SetValue(chromeDriver, "//*[@id='wiki-wrapper']/div[1]/h1", "myNewValue");

Click (IWebElement)

This method will click on an element.

Mandatory Parameters Optional Parameters
ChromeDriver chromeDriver int retries (default 15)
string xPath int retryInterval (default 1)
string text

Example:

WebEvents.ActionJs.Click(chromeDriver, "//*[@id='wiki-wrapper']/div[1]/h1", "myNewValue");

SearchJs

This subclass contains all of the methods that interact with the browser in JavaScript.

They are very agile and powerful and I recommend you use them only as a last resort.

Don't use a chainsaw to cut salmon.

FindAllChildren (List<IWebElement>)

This method will find all the children of an element. For example, if an element with a div tag has 3 children and those 3 children have 9 children each, then this method will return only the 3 children of the div tag.

Mandatory Parameters
ChromeDriver chromeDriver
IWebElement element

Example:

var allChildren = WebEvents.SearchJs.FindAllChildren(chromeDriver, element);

FindAllDescendants(List<IWebElement>)

This method will find all the children of an element. For example, if an element with a div tag has 3 children and those 3 children have 9 children each, then this method will return the 3 children of the div tag as well as the other 9 children each for each of the children.

Warning: This method can fail if there is a ShadowRoot present in the hierarchy.

Mandatory Parameters
ChromeDriver chromeDriver
IWebElement element

Example:

var allChildren = WebEvents.SearchJs.FindAllChildren(chromeDriver, element);

Clone this wiki locally