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,我想知道如果我的答案適合你? –