Chrisko Chrisko - 5 months ago 20x
Javascript Question

CasperJS loses select box vaue after submit

I have that select form:

<div class="row">
<div class="col-xs-18 form-group">
<label class="text-base" for="Gender">Geschlecht</label>
<select id="Gender" class="form-control" data-bind="value: gender, hasFocus: gender.focused, css: { 'has-error': showError(gender) }" name="Gender">
<option value="" selected="selected">Ausw&auml;hlen...</option>
<option value="m">M&auml;nnlich</option>
<option value="f">Weiblich</option>
<option value="u">Keine Angabe</option>
<div class="alert alert-error" aria-atomic="true" aria-relevant="text" aria-live="assertive" data-bind="errorMessage: gender, visible: showError(gender)" style="display: none;">Diese Informationen sind erforderlich.</div>

and filled it this way:

casper.then(function() {
this.evaluate(function(anrede_inside) {
document.querySelector('select#Gender').value = anrede_inside;
}, anrede);

so far its working great. but when i submit the page i get an error message that i haven't filled the gender value and the value is changed to the default value. i've checked it with screenshots.

submit is here on the page:

<div class="col-xs-18">
<input id="CredentialsAction" class="btn btn-primary btn-block" type="submit" value="Klick" title="Klick">

i click it like that:


i also tried to choose gender like that:

casper.then(function (){
this.sendKeys('select#Gender', 'w');

this is also working in the first moment, gender is choosen till i klick the submit button. any ideas what im doing wrong? or any ideas on wich other ways i could select the form?


ok, i tried every fill method. and finaly fixed it with:

 this.fillSelectors('form#formID', {
 'select[id=Gender]':    'm', //variable for gender
}, true);

the only problem is i get a warning in debug mode:

[warning] [remote] unable to submit form

but no problem at all.