javascripthtml-selectcasperjs

CasperJS loses select box vaue after submit


I have this 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>
   </select>
  <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>
</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">
</div>

I click it like that:

casper.then(function(){
    this.click('input[title*="Klick"]');
});

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 chosen till I click the submit button. Any ideas what I'm doing wrong? or any ideas on which other ways I could select the form?


Solution

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

    casper.then(function(){
     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.