Skip to main content

Interacting with Forms

Once you have queried the element you want to interact with, use the form property on any selected element to handle form input.

Filing out a form

Input Text

Using fill will replace any existing content within a textbox, so you do not need to separately clear it.

await element.form.fill("It's so easy!");

Clear Value

To remove all input from any form field.

await element.form.clear();

Check or Uncheck

To check a checkbox:

await element.check();

To uncheck a checkbox:

await element.check(false);

Select Option from Dropdown

To choose a dropdown option by its text:

await element.chooseOption("'Florida'");

To choose a dropdown option by its value:

await element.chooseOption("FL");

To choose a dropdown by its 0-based index in the dropdown list:

await element.chooseOption(7);

Choose a File

await element.chooseFile("./fixtures/logo.png");

Choose a Date

await element).chooseDate("2002-03-26");

Getting values from form inputs

value()

Select the value from any form control including textboxes, dropdowns, etc.

const value = element.value();

selectedText()

Instead of the value, if you want to get the text from the selected option on a dropdown.

const text = element.selectedText();

selectedIndex()

Get the zero-based index of the selected element of a dropdown.

const text = element.selectedText();

Asserting aginst form values

Must Have Value

Assert against the value of any form control.

await element.must.have.value("Jason");

Must Have Selected Text

Instead of the value, you want to assert the text of the selected option of a dropdown.

await element.must.have.selectedText("Florida");

Must Have Focus

await element.must.have.focus();

Must Be Checked

await element.must.be.checked();

Must Be Unchecked

await element.must.be.unchecked();

Must Be Disabled

await element.must.be.disabled();

Must Be Enabled

await element.must.be.enabled();

Must Be Valid

The value of this form input must be considered valid based on any criteria like min or max length, patterns, required, etc.

await element.must.be.valid();

Must Be Required

The form input must be marked required

await element.must.be.required();