Selenium questions - Galad/tranquire GitHub Wiki
Selenium questions allow you to retrieve values from the web browser.
All Selenium questions inherit from the UIState<T>
abstract class. They have common properties and methods.
When creating the question, it will search for a single element matching the target by default.
<div>Hello, world</div>
<div>Hello, folks</div>
actor.AsksFor(TextContent.Of(target));
// returns "Hello, world"
You can also request for all the elements matching the target using the Many
method.
actor.AsksFor(TextContent.Of(target).Many());
// returns ["Hello, world", "Hello, folks"]
A text in the UI interface may represent type other than string, for instance an integer.
You can convert the value to another type using some of the conversion methods.
<div>549</div>
actor.AsksFor(TextContent.Of(target).AsInteger());
// returns 549
The available conversion methods are
AsInteger
AsBoolean
AsDateTime
AsDouble
AsEnum
AsText
You can also create your own conversion by implementing IConverter<TSource, TConverter>
.
When using a conversion, you can specify the culture used to parse the text. For instance, when a text value "3,6" is converter to a double, you can specify that it should be parse with the french culture.
<div>3,6</div>
actor.AsksFor(TextContent.Of(target).WithCulture(CultureInfo.GetCultureInfo("fr-FR")));
// returns 3.6
Here are the available Selenium questions
The type of this question is ImmutableArray<string>
.
Returns the CSS classes of an element.
<div class="important completed">Do something important</div>
actor.AsksFor(Classes.Of(target));
// returns ["important", "completed"]
Returns the CSS classes of an element.
The type of this question is string
.
<div style="font-style: italic">Do something important</div>
actor.AsksFor(CssValue.Of(target).AndTheProperty("font-size"));
// returns "italic"
Returns Selenium IWebElement
matching the ITarget
.
The type of this question is IWebElement
.
<div>element</div>
actor.AsksFor(Element.Of(target));
// returns an IWebElement object corresponding to <div>element</div>
Returns a boolean value that is true
when the element is enabled and false
when it is disabled.
The type of this question is boolean
.
<input disabled="disabled">Hello, folks</div>
actor.AsksFor(Enabled.Of(target));
// returns false
Returns a the value of an attribute of an HTML element.
The type of this question is string
.
<div data="abc">Hello, folks</div>
actor.AsksFor(HtmlAttribute.Of(target));
// returns "abc"
Returns a boolean value indicating if the target is present in the DOM.
The type of this question is boolean
.
actor.AsksFor(Presence.Of(targetThatDoesNotExist));
// returns false
Returns a boolean value indicating whether the selectable input
target (such as a checkbox) is selected or not.
The type of this question is boolean
.
<input type="checkbox" name="item1" value="Item 1" checked="checked">
actor.AsksFor(Selected.Of(target));
// returns true
Returns the selected value of a <select>
element.
The type of this question is string
.
<select>
<option value="value1" selected="selected" />
<option value="value2" />
</select>
actor.AsksFor(SelectedValue.Of(target));
// returns "value1"
Returns the selected values of a <select>
element.
The type of this question is string[]
.
<select>
<option value="value1" selected="selected" />
<option value="value2" selected="selected" />
</select>
actor.AsksFor(SelectedValues.Of(target));
// returns ["value1", "value2"]
Returns the text content of an element.
The type of this question is string
.
<div>Hello, folks</div>
actor.AsksFor(TextContent.Of(target));
// returns "Hello, folks"
Returns the value of an input element.
The type of this question is string
.
<input value="value1" />
actor.AsksFor(Value.Of(target));
// returns "value1"
Returns whether the element is visible or not.
The type of this question is boolean
.
<div style="display: none">Hello, folks</div>
actor.AsksFor(Visibility.Of(target));
// returns false
Returns a the HTML page title.
<head>
<title>This is the page</title>
actor.AsksFor(Page.Title());
// returns "This is the page"
Returns the current page URL.
actor.When(Navigate.To("https://www.google.com"));
actor.AsksFor(Page.Url());
// returns "https://www.google.com"
Returns the page source code.
<html>
<body>
<div>Hello, folks</div>
</body>
</html>
actor.AsksFor(Page.Html());
// returns "<html>
<body>
<div>Hello, folks</div>
</body>
</html>"