Table of Contents

Interface ITarget

Namespace
CSF.Screenplay.Selenium.Elements
Assembly
CSF.Screenplay.Selenium.dll

A target is an object which represents one or more HTML elements and which may serve as parameters for performables which interact with elements on the web page.

public interface ITarget : IHasName
Inherited Members
Extension Methods

Remarks

See the targets and elements article for more information. The ITarget interface unifies two Selenium concepts: IWebElement instances and the By class. Targets correspond to the concept of HTML elements on a web page and may be used as the parameters for performable classes which interact with those elements.

The SeleniumElement and SeleniumElementCollection classes wrap native Selenium web element instances. They are concrete references to elements which have been retrieved from the WebDriver. In both of these cases, the GetElement(IWebDriver) & GetElements(IWebDriver) methods will often return references to themselves without making any use of the WebDriver parameter.

On the other hand, targets which derive from Locator, such as ElementId, ClassName, CssSelector and XPath identify HTML element(s) without being a concrete reference to them. A Locator is conceptually 'a specification for finding elements'. Locator-based targets will use the WebDriver parameter in their GetElement(IWebDriver) and GetElements(IWebDriver) methods, in order to retrieve concrete element references.

Methods

GetElement(IWebDriver)

Gets a single Selenium element which matches the current target.

SeleniumElement GetElement(IWebDriver driver)

Parameters

driver IWebDriver

A Selenium Web Driver

Returns

SeleniumElement

A SeleniumElement which matches the target

Remarks

This method may invoke the specified Selenium IWebDriver to get the element which matches a specification/selector. Alternatively if the target implementation already represents one or more concrete element instances then it will be returned directly. Crucially, if the target represents multiple elements then this method will return only the first element.

Exceptions

TargetNotFoundException

If the target does not yield an HTML element

GetElements(IWebDriver)

Gets a collection of Selenium elements which match the current target.

SeleniumElementCollection GetElements(IWebDriver driver)

Parameters

driver IWebDriver

A Selenium Web Driver

Returns

SeleniumElementCollection

A collection of zero or more Selenium elements

Remarks

This method may invoke the specified Selenium IWebDriver to find elements which match a specification/selector. Alternatively if the target implementation already represents one or more concrete element instances then these will be returned directly.