如何使用CasperJS将选项值插入到选择标记中?

问题描述 投票:0回答:1

嗯,这个问题非常明显。

现在,我在一个表格的前面,这个表格已经有一些选项标签。但我必须插入一个新的,具有不同的值,我将从.json文件中收到。

问题是:我无法从CasperJS文档中找到合适的解决方案。

我尝试过这样的事情:

this.fill('form.coworkerdiscountcode', {
'CoworkerDiscountCode.DiscountCode': ['Value1'] 
});

但没有结果。有任何想法吗?

提前致谢。

select phantomjs casperjs
1个回答
0
投票

您可以通过将其传递给casper.evaluate来执行任何javascript代码,如下所示:

casper.evaluate(function() {
    var x = document.getElementById("coworkerdiscountcode");
    var option = document.createElement("option");
    option.text = "Kiwi";
    x.add(option);
});
© www.soinside.com 2019 - 2024. All rights reserved.