2015-09-25 77 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。