Table of Contents

Class Locator

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

An object which provides a locator for Selenium elements.

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

Remarks

The Selenium By object is a specification of sorts, which can be used to find HTML elements on a web page. Concrete implementations of this class provide various ways to get a By object.

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 OpenQA.Selenium.By object.

public static implicit operator By(Locator locator)

Parameters

locator Locator

The locator to convert.

Returns

By

A Selenium OpenQA.Selenium.By object.