Table of Contents

Class Locator

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

Base type for implementations of ITarget which serve as a specification for Selenium elements but which do not reference those elements directly.

public abstract class Locator : ITarget, IHasName
Inheritance
Locator
Implements
Derived
Inherited Members
Extension Methods

Remarks

All derived types of this class are Screenplay wrappers (adapters) for the Selenium By class. The 'By' class is a specification of sorts, describing how a WebDriver may find an element on a page. Implementations of this type provide that specification, but additionally a Name, providing human-readable content in Screenplay reports.

Constructors

Locator(string, string)

Initializes a new instance of the Locator class.

protected Locator(string specification, string name = null)

Parameters

specification string

The locator specification string.

name string

An optional human-readable name of the locator which describes the elements it matches.

Properties

Name

Gets the human-readable name of the current object.

public string Name { get; }

Property Value

string

Remarks

null is strongly discouraged here. All types which implement IHasName should return a non-null response from this property.

Specification

Gets the locator specification string.

protected string Specification { get; }

Property Value

string

Methods

GetDefaultName()

Gets a value for Name if none has been specified.

protected abstract string GetDefaultName()

Returns

string

A default name

GetElement(IWebDriver)

Gets a single Selenium element which matches the current target.

public 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.

public 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.

GetLocator()

Gets the Selenium locator instance for finding HTML elements.

public abstract By GetLocator()

Returns

By

A Selenium By object used to locate elements.

Operators

implicit operator By(Locator)

Implicitly converts a Locator to a Selenium By object.

public static implicit operator By(Locator locator)

Parameters

locator Locator

The locator to convert.

Returns

By

A Selenium By object.