我多次在长脚本中使用以下代码:
this.click("<selector>");
但有一页不起作用,我不明白为什么。
HTML是:
<div class="bottom-row">
<div class="actions-primary">
<button class="add-subscription button middle" id="2">Choose</button>
</div>
</div>
所以我正在使用:
casper.waitUntilVisible('#products_screen',
function success() {
casper.test.pass('Product List Show');
this.echo(this.getHTML('.actions-primary'));
//this.click("button#2.add-subscription.button.middle");
this.click("#2");
},
function fail() {
casper.test.fail('List of Products not showing');
},
50000);
我尝试了所有可能没有运气的选择器。
此外,如果我在Chrome中尝试使用Resurrectio,它也不会记录点击。
欢迎任何解决方法。
解决方案更新:
this.click('[id="2"]');
答案 0 :(得分:0)
我使用css选择器格式解决它:
this.click('[id="2"]');
答案 1 :(得分:0)
如果id
是一个数字,则必须根据Unicode代码点对数字进行转义,或使用属性选择器。
以下两种解决方案都可以使用:
this.click('#\\32 '); // Escaped based on Unicode code point
this.click('[id="2"]'); // Attribute selector