使用PhantomJS测试ReactJS - 更改SELECT值

时间:2017-09-05 06:44:04

标签: jquery reactjs phantomjs

我试图用PhantomJS测试ReactJS,

我似乎无法触发更改SELECT事件:

                selectWidth = [];
                selectPath =  $("#pdp-width-select").first()
                options = $("option", selectPath);
                options.each(function () {
                    $(this).attr("selected","selected");
                    $(this).trigger("change");
                    selectWidth.push({
                        text: $(this).text(),
                        value: $(this).val(),
                        stock: $("._1HQVd").text()
                    })
                })

此代码尝试触发更改事件并获取股票值。

但它不起作用。

我也尝试过这种方法:

Change the selected value of a drop-down list with jQuery

How to Change select value using PhantomJS

How to trigger event in JavaScript?

                selectWidth = [];
                selectPath =  $("#pdp-width-select").first()
                options = $("option", selectPath);
                options.each(function (i) {
                    selectPath[0].selectedIndex = i;
                    selectWidth.push({
                        text: $(this).text(),
                        value: $(this).val(),
                        stock: $("._1HQVd").text()
                    })
                })

注意:我也无法在Chrome开发工具中使用它。

1 个答案:

答案 0 :(得分:0)

溶液

/**
  Draw a Hexagon shape with 6 sides
  @Param {Number} x horizontal center
  @Param {Number} y vertical center
  @Param {Number} r radius
 */
CanvasRenderingContext2D.prototype.hexagon = function(x, y, r) {
  var a = Math.PI2 / 6;

  this.beginPath();
  this.translate(x, y);
  this.moveTo(radius, 0);

  for (var i = 1; i < sides; i++) {
    this.lineTo(radiusMath.cos(ai), radiusMath.sin(ai));
  }
  this.closePath();
};

evtName = 'change'; var event = document.createEvent("MouseEvents"); event.initMouseEvent(evtName, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);