2015-09-25 34 views
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並輸入帖子的描述。任何人都可以知道如何做到這一點?

回答

0

您是否嘗試過使用此casper方法withFrame()來訪問與最新版本相關的幀。

casper.open("http://www.example.com", function() { 
    casper.withFrame('your-frame', function() { 
     this.test.assertSelectorExists('#id-selector-inside-frame', 'Selector found'); 
    }); 
    }); 

的文檔是在這裏 http://casperjs.readthedocs.org/en/latest/modules/casper.html#withframe

+0

但對於iframe中沒有名字。它只有一個ID。