Use a select outside of a form with CasperJS

北城余情 提交于 2019-12-01 09:27:59

问题


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.

回答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.



来源:https://stackoverflow.com/questions/22508688/use-a-select-outside-of-a-form-with-casperjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!