【问题标题】:How to check a radio have onclick with caperjs?如何使用 caperjs 检查收音机是否有 onclick?
【发布时间】:2016-06-06 17:10:15
【问题描述】:

这是我的代码:

完整代码在这里:http://notepad.cc/casperjsstack1

this.thenOpen('https://www.1800flowers.com/webapp/wcs/stores/servlet/FDDeliveryOptionsDisplayCmd', function() {
  this.waitForSelector('#BP-DeliveryCardMess_1', function() {
    this.evaluate(function() {
      var el = $('#giftMessages.noCard');
      el.onclick();
    });
  });
});

看图:我要查无礼物留言

我尝试了很多方法但都是错误的

在此处编码 HTML 页面:http://notepad.cc/casperjsstack1_html

谢谢!

【问题讨论】:

  • @artjom-b 请帮帮我

标签: javascript jquery html casperjs


【解决方案1】:

你试过click()吗?

this.thenOpen('https://www.1800flowers.com/webapp/wcs/stores/servlet/FDDeliveryOptionsDisplayCmd', function() {
    this.waitForSelector('#BP-DeliveryCardMess_1', function() {
        this.evaluate(function() {
            this.click('#giftMessages.noCard'); // Click the radio button.
        });
    });
});

【讨论】:

    【解决方案2】:

    试试这个。

    //jQuery version using evaluation page context
    this.thenOpen('https://www.1800flowers.com/webapp/wcs/stores/servlet/FDDeliveryOptionsDisplayCmd', function() {
        this.waitForSelector('#BP-DeliveryCardMess_1', function() {
            this.evaluate(function() {
                $("#giftMessages.noCard").prop("checked", true).trigger("click");
            });
        });
    });
    
    //Casper version using click
    this.thenOpen('https://www.1800flowers.com/webapp/wcs/stores/servlet/FDDeliveryOptionsDisplayCmd', function() {
        this.waitForSelector('#BP-DeliveryCardMess_1', function() {
            this.click("#giftMessages.noCard");
        });
    });
    

    【讨论】:

      猜你喜欢
      • 2015-08-26
      • 2016-05-29
      • 2014-04-15
      • 1970-01-01
      • 2013-11-20
      • 1970-01-01
      • 1970-01-01
      • 2010-12-20
      • 1970-01-01
      相关资源
      最近更新 更多