0
我正在使用casperjs登录linkedin并发布帖子。Casperjs要在linkedin中发布帖子
var casper = require('casper').create({
logLevel: "info", // Only "info" level messages will be logged
verbose: true , // log messages will be printed out to the console
waitTimeout: 50000
});
casper.start('https://www.linkedin.com/uas/login', function() {
this.echo(this.getTitle());
});
casper.thenEvaluate(function(term){
document.querySelector('input[id="session_key-login"]').setAttribute('value',term);
},'username');
casper.thenEvaluate(function(term){
document.querySelector('input[id="session_password-login"]').setAttribute('value',term);
},'password');
casper.then(function(){
this.click('input[name="signin"]');
console.log("clicking..........");
this.capture("linkedin.png");
});
casper.waitForSelector('a.publish', function() {
this.click('a.publish');
});
casper.waitForSelector('article.stream-article ', function() {
this.fillSelectors('article.stream-article',{
'textarea.title':'This is title',
},false);
this.capture('linked3.png');
this.capture('linked4.png');
});
casper.then(function(){
this.sendKeys('textarea.title',"casper.page.event.key.Tab");
this.capture('linkedin5.png');
});
casper.then(function(){
this.fillSelectors('iframe[id^="editor-textarea"]',{
'p':'This is title',
},false);
});
casper.run();
我能够登录并键入帖子的标题,但我无法选择iframe并输入帖子的描述。任何人都可以知道如何做到这一点?
但对于iframe中没有名字。它只有一个ID。
是的,但根据文档'withFrame'可以通过索引处理iframe。因此,如果你发现文本编辑器的索引(在你的情况下它将是2),你可以使用这样的代码: 'casper.withFrame(2,function(){this.sendKeys('#tinymce','teeeeest ');});' –
@Nisthar,我想知道如果我的答案适合你? –