单击特定CasperJS按钮不起作用

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

我在很长的脚本中多次使用以下代码:

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"]');
javascript phantomjs automated-tests casperjs
2个回答
0
投票

我用css选择器格式解决它:

this.click('[id="2"]');

0
投票

如果id是一个数字,则必须根据Unicode代码点转义该数字,或使用属性选择器。

以下两种解决方案都可以使用:

this.click('#\\32 ');    // Escaped based on Unicode code point
this.click('[id="2"]');  // Attribute selector
© www.soinside.com 2019 - 2024. All rights reserved.