使用CasperJS在表单外部选择一个选择 [英] Use a select outside of a form with CasperJS

查看:122
本文介绍了使用CasperJS在表单外部选择一个选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想选择一个入选项。
我如何用CasperJS做到这一点。



您需要知道的一些信息:


  • 我无法修改该页面。我的任务只是编写测试。
  • 选择标记不包含在表单中。
  • 我不能使用 document.querySelector(MY_SELECT).selectedIndex = X; 方法,因为更改select(具有正常行为)会抛出一些我需要的事件,并且它们不会以简单的形式抛出。 $ b

解决方案

您是否想模拟正常行为?这是正确的在某些问题操纵DOM是不够的(事件不会被抛出,所以你不能发送你的表单,因为数据没有更新,并且你有ajax返回的错误)。我已经意识到,当我们进行功能测试时,重现用户行为始终有效:) - >

  this.mouse .down(select元素的选择器); //按左键
this.mouse.up('select元素选项的选择器'); //释放左键

示例:

  this .mouse.down(div#ec1 select.jCustomSelect.monthB); //按左键
this.mouse.up('div#ec1 select.jCustomSelect.monthB> option [value =7 ]'); //释放左键

或者你可以使用jQuery和change()方法。

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.

解决方案

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.

这篇关于使用CasperJS在表单外部选择一个选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆