I am automating testing of a web page in which there exists two multi select fields on a form. The one on the left contains a list of country names, the one on the right contains the ones you have selected. Countries can exist on one list but not the other. When you click a country it moves to the other list (you get the idea). When the form is submitted the values in the POST look like this (from chrome inspection):
data[Campaign][unselected_country_codes]: data[Campaign][unselected_country_codes][]:AF data[Campaign][unselected_country_codes][]:AX data[Campaign][unselected_country_codes][]:AL data[Campaign][unselected_country_codes][]:DZ data[Campaign][unselected_country_codes][]:AS data[Campaign][unselected_country_codes][]:AD data[Campaign][unselected_country_codes][]:AO data[Campaign][unselected_country_codes][]:AI data[Campaign][unselected_country_codes][]:AG data[Campaign][unselected_country_codes][]:AR ... (ALL countries not selected are in this list) data[Campaign][country_codes]: data[Campaign][country_codes][]:US data[Campaign][country_codes][]:AQ data[Campaign][country_codes][]:BD ... (this part contains the ones we have selected)
and here is what the HTML looks like for the select list of the countries you want included:
<select name="data[Campaign][country_codes][]" multiple="multiple" id="CampaignCountryCodes" data-quicklist-ref="CampaignCountryCodes_quick" data-alter-ref="CampaignCountryCodes_alter">
<option value="US" selected="selected">United States</option>
<option value="AQ" selected="selected">Antarctica</option>
<option value="BD" selected="selected">Bangladesh</option>
</select>
What I don't understand is, how would I set those form values at the time of testing? I don't really understand the <select>
attribute of a form comes through as an array of values or what? I would like to be able to submit the form and have a list of countries that are on, and a list that are off.
Here is an example of what I do to set other values on the form that works correctly. I really have no idea how to do this for a multiple and that is the question being asked.
This example is a text area that works just great.
casper.waitForSelector(x('//*[@id="some text area"]'),
function success() {
test.assertExists(x('//*[@id="some text area"]'));
this.fill('form#campaign_form', {
'data[Campaign][some_field]': 'include',
'data[Campaign][the_field]': myvar + "\n"
}, true);
},
function fail() { ... }
);