Table of Contents

Class SendKeys

Namespace
CSF.Screenplay.Selenium.Actions
Assembly
CSF.Screenplay.Selenium.dll

A partial Screenplay Action which sends keys (enters text) to an HTML element.

public class SendKeys : ISingleElementPerformable, ICanReportForElement
Inheritance
SendKeys
Implements
Inherited Members

Examples

This example types "Jane Doe" into the element with ID name.

using CSF.Screenplay.Selenium.Elements;
using static CSF.Screenplay.Selenium.PerformableBuilder;

readonly ITarget name = new ElementId("name", "the name field");

// Within the logic of a custom task, deriving from IPerformable
public async ValueTask PerformAsAsync(ICanPerform actor, CancellationToken cancellationToken = default)
{
    // ... other performance logic
    await actor.PerformAsync(EnterTheText("Jane Doe").Into(name), cancellationToken);
    // ... other performance logic
}

Remarks

Use this action via the builder method EnterTheText(params string[]). Performing this action, as an actor which has the BrowseTheWeb ability, instructs the web browser to press the specified keys, essentially entering text into the HTML element indicated by the target.

Typically, this action is performed upon an element which supports user-input such as an <input> or <textarea> element. However, it is not limited to these elements; any element may receive key-presses.

You may send non-printable or special keys such as Enter or directional arrow key-presses by using Selenium's Keys class.

This class is not a complete performable, as it relies upon shared logic to retrieve the SeleniumElement upon which it shall act. It has this in common with many Screenplay actions & tasks in the Selenium extension which operate upon a single element. These performables derive from ISingleElementPerformable. In order for this class to be used as a full-fledged performable, an instance of this type must be wrapped within an instance of SingleElementPerformableAdapter. The adapter class provides the shared boilerplate logic which provides access to the Selenium Element. Note that the builder method(s) which create instances of this type include the 'wrap within an adapter' logic. Normal usage of this performable, when creating it from a builder, does not need to be concerned with this factor.

Constructors

SendKeys(string)

Initializes a new instance of the SendKeys class with the specified text.

public SendKeys(string text)

Parameters

text string

The text to enter into the element.

Methods

GetReportFragment(Actor, Lazy<SeleniumElement>, IFormatsReportFragment)

Counterpart to GetReportFragment(Actor, IFormatsReportFragment) except that this method also offers a Selenium element.

public ReportFragment GetReportFragment(Actor actor, Lazy<SeleniumElement> element, IFormatsReportFragment formatter)

Parameters

actor Actor

An actor for whom to write the report fragment

element Lazy<SeleniumElement>

The Selenium element for which the report is being written

formatter IFormatsReportFragment

A report-formatting service

Returns

ReportFragment

A human-readable report fragment.

Remarks

Please see the documentation for GetReportFragment(Actor, IFormatsReportFragment) for more information.

PerformAsAsync(ICanPerform, IWebDriver, Lazy<SeleniumElement>, CancellationToken)

Counterpart to PerformAsAsync(ICanPerform, CancellationToken) except that this method also offers a Selenium WebDriver and element.

public ValueTask PerformAsAsync(ICanPerform actor, IWebDriver webDriver, Lazy<SeleniumElement> element, CancellationToken cancellationToken = default)

Parameters

actor ICanPerform

The actor that is performing.

webDriver IWebDriver

The Selenium WebDriver provided from the actor's abilities.

element Lazy<SeleniumElement>

The single Selenium Element upon which this method should operate.

cancellationToken CancellationToken

An optional cancellation token by which to abort the performable.

Returns

ValueTask

A task which completes when the performable represented by the current instance is complete.

See Also

EnterTheText(params string[])