我有一个casperjs问题。 我无法从JavaScript的ID中获取价值。
我打开谷歌,搜索的术语,我想从ID搜索框的值。
var casper = require('casper').create({
verbose: true,
logLevel: "info"
});
var mouse = require("mouse").create(casper);
var x = require('casper').selectXPath;
var webPage = require('webpage');
var page = webPage.create();
casper.userAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.65 Safari/537.36')
casper.start("http://www.google.com/ncr", function () {
this.echo(this.getTitle());
}).viewport(1366, 768);
//casper.then(function() {
//this.sendKeys('#gbqfq', 'Duke');
//this.click('#gbqfsa');
//});
casper.waitForSelector(x('//*[@id="gbqfq"]'), function () {
this.evaluate(function () {
document.getElementById('gbqfq').value = "samearga";
this.echo(this.document.getElementById('gbqfq').value);
});
console.log("\nEXISTA SELECTORUL!!! -> document.getElementById('gbqfq').value\n");
});
casper.waitForSelector(x('//*[@id="gbqfq"]'), function () {
this.evaluate(function () {
document.forms[0].submit();
});
console.log("\nSUBMITING!!!\n");
});
casper.wait(4000, function () {
console.log("\nFAC POZA\n");
casper.capture('caca.png');
});
casper.run();