Skip to content

WebEvents.SearchJs

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

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 allDescendants= WebEvents.SearchJs.FindAllDescendants(chromeDriver, element);

FindWebElementByXPathWindowless (IWebElement)

This method will search for the element with the specified XPath recursively in all existing IFrames of the currently active page, it will make no effort to switch to any other windows, pages or tabs to search for the element with the specified XPath.

**Warning: ** For this method there are no retries or retry intervals, it only executes once, and if it fails it will throw an Exception.

Mandatory Parameters Optional Parameters
ChromeDriver chromeDriver string FrameType (default "iframe")
string XPath

Example:

var element = WebEvents.SearchJs.FindWebElementByXPathWindowless(chromeDriver, "//*[@id='wiki-wrapper']/div[1]/h1");

FindWebElementByXPath (IWebElement)

This method will search for the element with the specified XPath recursively in all existing IFrames of the currently active page, it will make effort to switch to every other windows, pages or tabs to search for the element with the specified XPath.

**Warning: ** For this method there are no retries or retry intervals, it only executes once, and if it fails it will throw an Exception.

Mandatory Parameters Optional Parameters
ChromeDriver chromeDriver string FrameType (default "iframe")
string XPath

Example:

var element = WebEvents.SearchJs.FindWebElementByXPath(chromeDriver, "//*[@id='wiki-wrapper']/div[1]/h1");

WaitElementAppear(IWebElement)

This method will search for the element with the specified XPath recursively in all existing IFrames of the currently active page, it will make effort to switch to every other windows, pages or tabs to search for the element with the specified XPath, it will also retry to find the element in a set interval.

Mandatory Parameters Optional Parameters
ChromeDriver chromeDriver int retries (default 15)
string XPath int retryInterval (default 1)
  string FrameType (default "iframe")

Example:

var element = WebEvents.SearchJs.WaitElementAppear(chromeDriver, "//*[@id='wiki-wrapper']/div[1]/h1");

Clone this wiki locally