2

I want to select an entry into a select. How I can do that with CasperJS.

Some information you need to know :

  • I can't modify the page. My task is only to write the test.
  • The select markup is not included in a form.
  • I cannot use the document.querySelector(MY_SELECT).selectedIndex = X; method because changing the select (with normal behaviour) throw some event I need, and they are not thrown with simple affectation.
Farid Nouri Neshat
  • 29,438
  • 6
  • 74
  • 115
Aurélien B
  • 4,590
  • 3
  • 34
  • 48

1 Answers1

1

Do you want to just simulate the normal behaviour? That's right in some issue manipulate the DOM isn't sufficient (the events are not thrown and so you can't send your form because the data isn't updated, and you have the errors of the ajax return). I've realized that when we're doing functional test, reproduce the user behaviour always works :) ->

this.mouse.down("selector of your select element");//press left button 
this.mouse.up('selector of the option of your select element');//release left button

Example :

this.mouse.down("div#ec1 select.jCustomSelect.monthB");//press left button 
this.mouse.up('div#ec1 select.jCustomSelect.monthB > option[value="7"]');//release left button

Or you could use jQuery and the change() method.

Fanch
  • 3,274
  • 3
  • 20
  • 51