Appearance
Typing into fields
Filling forms is one of the most common actions on a webpage. Nearly every workflow involves entering text into a form field.
Filling input fields using I.fill
In most cases, the easiest way to fill an input field is to use the I.fill command:
js
// using text
I.fill("First Name", "John")
// using CSS
I.fill("#last-name-input", "Doe")
// using XPath
I.fill("//input[name='username']", "johndoe")I.fill() accepts two arguments:
element: the input field to target — by visible text, descriptive attribute, or CSS or XPath selectorvalue: the value to fill into the input
The command will perform the following in sequence automatically:
- Set focus on the input field
- Clear any existing value
- Type the value into the input field, one character at a time
How UI-licious identifies fields to fill
We strongly recommend using human-facing labels to target input fields, instead of CSS or XPath selectors, because it keeps tests readable and resilient to UI changes.
To find the best match for I.fill(), UI-licious evaluates potential targets based on intent — how strongly each element appears to be the input the tester meant to interact with.
UI-licious ranks matches in the following order of priority:
- associated
<label>elements - visible text content such as
placeholderor the field's rendered value - descriptive attributes such as
aria-labelortitle - the
nameattribute on the input element - surrounding or adjacent text
If multiple elements score equally based on intent, UI-licious chooses the element closest to other recently interacted elements.
This helps maintain context when multiple similar fields appear on the screen.
INFO
I.fill() strictly only targets <input> elements that accept text input and <textarea> elements.
To send keystrokes to non-standard editable content such as WYSIWYG rich text editors or contenteditable elements, use the I.type() command instead.
Typing into input fields using I.type
In some situations, it is more appropriate to use I.type of I.fill:
- when targeting a WYSIWYG rich text editor or a
contenteditableelement - when you want to modify instead of replace the value in the field
Unlike I.fill, I.type() sends keystrokes to the active element at the current cursor position. Before using I.type(), you should set the focus on the input element:
js
I.click("#biography-editor")
I.type(`My favorite movie is "Finding Nemo".`)Clearing input fields
To clear an input field, you may use I.fill() with an empty value, or I.clear():
js
I.fill("First name", "")
I.clear("Last name")Verifying field values
To assert that an input field is filled with a specific text, use I.filled.
js
I.filled("First name", "John")