Javascript 用Phantomjs测试AngularJS
我试图用PhantomJS测试AngularJS教程()。我无法让键入的搜索实际运行 以下是我目前的情况:Javascript 用Phantomjs测试AngularJS,javascript,angularjs,phantomjs,Javascript,Angularjs,Phantomjs,我试图用PhantomJS测试AngularJS教程()。我无法让键入的搜索实际运行 以下是我目前的情况: 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", functio
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()
});
});
直接更改输入值时,绑定似乎不起作用。您需要使用PhantomJS的本机输入法
当函数被执行时,我不得不做一些工作来分离,但是page.sendEvent(“keypress”,“xoom”);我成功了!当要与之交互的元素为select时,如何继续?不幸的是,这种方法不起作用…@Puce关注
select
元素和page.sendEvent(“按键”,page.event.key.Down)代码>您需要的数量。我想Fanch在去年的选择中提到了这个方法。谢谢!我使它能够工作:$(“.select.selectId”).val(selectedValue.trigger('change')代码>
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();
});