好的,有人能帮我吗?我是刚接触过casperjs的人,到目前为止,堆积如山真是太棒了,这里的人都很有帮助。
在最终使我的脚本工作并使它回显html之后,我想添加一个新的函数,并需要关于如何实现它的帮助。
基本上,而不是回显出html。
我想检查一下xpath是否存在,如果它存在,我希望它回显
you still have minutes 如果它不存在回声
no minutes left 这里是我想检查的xpath
/html/body/div/div[3]/div[2]/div/div/table/tbody/tr[2]/td[2]有人能给我看一个简单的函数吗?
我的职能
// Wait 2 sec then write to txt file
casper.wait(9000, function() {
//this.echo(this.getHTML());
//this.echo(this.getCurrentUrl());
this.fill('form[name="LoginForm"]', {
'username': 'test',
'password': 'test'
}, true);
});发布于 2014-01-28 10:14:25
好的,我不再使用xpath,而是返回到css选择器,这里介绍了我是如何解决问题的
if (this.exists('div.box_pink div.inner p')) {
this.echo('the css selector exists'); } else {
this.echo('the css selector dont exist');
}
});发布于 2014-01-27 18:04:30
像这样吗?我根据你提供的代码做了修改。
casper.start('http://yoursite.tld/', function() {
// Wait 2 sec then write to txt file
this.wait(9000, function() {
//this.echo(this.getHTML());
//this.echo(this.getCurrentUrl());
this.fill('form[name="LoginForm"]', {
'username': 'test',
'password': 'test'
}, true);
if(this.exists('/html/body/div/div[3]/div[2]/div/div/table/tbody/tr[2]/td[2]')) {
console.log('you still have minutes');
}
else {
console.log('no minutes left');
}
});
});
casper.run();https://stackoverflow.com/questions/21388206
复制相似问题