Skip to content

SeleniumCheckableGroupInputWebElement

Mark Reeves edited this page Jan 4, 2018 · 4 revisions

SeleniumCheckableGroupInputWebElement is an extension of SeleniumGroupInputWebElement which is specifically concerned with groups of checkable inputs.

The WComponents which may be tested using SeleniumCheckableGroupInputWebElement are:

  • WCheckBoxSelect (using com.github.bordertech.wcomponents.test.selenium.element.SeleniumWCheckBoxSelectWebElement); and
  • WRadioButtonSelect (using com.github.bordertech.wcomponents.test.selenium.element.SeleniumWRadioButtonSelectWebElement).

Getting options

List<WebElement> getOptions() will return all options in the current component. If the component is in a read-only state then this will comprise all selected options.

Getting a specific option

A specific option may be obtained by index or using its label text.

// given SeleniumWCheckBoxSelectWebElement element
// get 3rd option by index
WebElement option = element.getOption(2);

// get option by using its labelText
WebElement option = element.getOption("New South Wales");

Interacting with options

Options may be interacted with based on their index, label text or by accessing the option's WebElement obtained from one of the getOption methods.

Selected state

An option may be selected or have its selected state queried. See testing WCheckBoxSelect for information about deselecting and toggling options. Options in a WRadioButtonSelect may only be selected: this will automatically deselect a previously selected option.

// given SeleniumWCheckBoxSelectWebElement element

// to select the 'nth' option:
element.select(n);
// to select the NSW option:
element.select("New South Wales");
// to select a previously obtained option WebElement `option`
element.select(option);

// to query the selected state of the nth option:
boolean isSelected = element.isSelected(n);
// etc...
isSelected = element.isSelected("New South Wales");
isSelected = element.isSelected(option);

Clicking an option

An option may be clicked in a Selenium test. This is a good way to simulate a user interaction for selecting an option. There are two mechanisms for firing clicks. The default will cause the test to wait until the page is again marked as ready which will cause your tests to run more slowly but is required if the click will cause an Ajax or Subordinate action.

// given SeleniumWCheckBoxSelectWebElement element

// to click the 'nth' option:
element.click(n);
// to click the NSW option:
element.click("New South Wales");
// to click a previously obtained option WebElement `option`
element.click(option);

To click an option without waiting for the page to be made ready afterwards (if one knows the control is not causing an Ajax interaction for example) one can use the methods clickNoWait.

// given SeleniumWCheckBoxSelectWebElement element

// to click the 'nth' option:
element.clickNoWait(n);
// to click the NSW option:
element.clickNoWait("New South Wales");
// to click a previously obtained option WebElement `option`
element.clickNoWait(option);

Getting the HTML form control

The interactive HTML form control input element for an option may be obtained as a WebElement for further manipulation. This will throw an Exception if the WComponent is in a read-only state.

// given SeleniumWCheckBoxSelectWebElement element

// to get the HTML input element of the nth option:
WebElement input = element.getInput(n);
// to get the HTML input element of the NSW option:
input = element.getInput("New South Wales");
// to get the HTML input element of a previously obtained `option`
input = element.getInput(option);

Related components

Further information

Clone this wiki locally