我正在尝试用AngularJS教程(http://angular.github.io/angular-phonecat/step-7/app)来测试PhantomJS。我无法输入搜索才能真正运行。
到目前为止,我的情况如下:
var page = new WebPage();
page.open('http://angular.github.io/angular-phonecat/step-7/app', function() {
page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function() {
page.evaluate(function() {
$("[ng-model=query]").click();
$("[ng-model=query]").focus();
$("[ng-model=query]").val("xoom");
console.log($('ul.phones').text());
});
phantom.exit()
});
});发布于 2014-10-21 20:14:13
直接更改输入值时,绑定似乎不起作用。您需要使用PhantomJS的本机输入方法sendEvent。
page.open('http://angular.github.io/angular-phonecat/step-7/app', function() {
page.evaluate(function() {
document.querySelector('[ng-model=query]').focus();
});
page.sendEvent("keypress", "xoom");
page.evaluate(function() {
console.log(document.querySelectorAll('ul.phones li').length + " products");
});
phantom.exit();
});https://stackoverflow.com/questions/26494826
复制相似问题