[英]Clicking Specific CasperJS Button Not Working
I am using the following code in a long script many times: 我在长脚本中多次使用以下代码:
this.click("<selector>");
But there is one page that doesn't work, and I don't understand why. 但是有一页无法使用,我也不明白为什么。
The HTML is: HTML是:
<div class="bottom-row">
<div class="actions-primary">
<button class="add-subscription button middle" id="2">Choose</button>
</div>
</div>
So I am using: 所以我正在使用:
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);
I tried all possible selectors with no luck. 我没有运气就尝试了所有可能的选择器。
Also, if I try with Resurrectio in Chrome, it doesn't record the click. 另外,如果我尝试在Chrome中使用Resurrectio,则不会记录点击。
Any workaround is welcome. 任何变通方法都欢迎。
SOLUTION UPDATE: 解决方案更新:
this.click('[id="2"]');
我使用CSS选择器格式解决它:
this.click('[id="2"]');
If an id
is a number, you must either escape the number based on the Unicode code point, or use the attribute selector. 如果id
是数字,则必须根据Unicode代码点对数字进行转义,或者使用属性选择器。
Both of the following solutions will work: 以下两种解决方案都可以使用:
this.click('#\\32 '); // Escaped based on Unicode code point
this.click('[id="2"]'); // Attribute selector
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.