在我的测试中,我需要等待页面加载才能继续。因为某些原因,waitForSelector
和waitForText
不工作,虽然我可以只使用wait(value)
,但我必须考虑服务器可能会变慢的时间,并使价值比我想要的大得多;所以我正在考虑做一个while循环,告诉系统每次返回时等待500毫秒,因为页面上不存在'someCSSpath'。有没有办法做到这一点(可能是“casper.DoesntExist'?),或者没有更好的办法来做到这一点?等待页面加载CasperJS
var css3path = "body > div.container-fluid > div:nth-child(3) > div.row.ng-scope > div:nth-child(1) > a > div";
casper.waitForSelector(css3path , function(){
this.test.assertExists(css3path);
if (casper.exists(css3path){
this.echo("logged in!");}
else{
this.echo("not logged in");
};
});
当我使用一个casper.wait(6000, function(){
而不是waitForSelector
,它工作正常。
我使用waitforselector以及相同的格式,这也是可行的;我认为这是我正在寻找的具体事情,这给我带来麻烦
此外,当我使用wait(6000,
测试发现CSS3路径就好了;它只是waitForSelector
找不到它
这正是'waitForSelector()'。你可能没有正确使用它。请显示您的代码,您希望发生什么以及实际发生了什么(包括错误消息,屏幕截图说明)。为了安全起见:请注册到'resource.error','page.error','remote.message'和'casper.page.onResourceTimeout'事件([Example](https://gist.github。 COM/artjomb/4cf43d16ce50d8674fdf))。也许有错误。 –
您确定存在CSS选择器。也许你正在检查一个基于桌面的CSS选择器,但PhantomJS加载了没有这种选择器的移动网站。 –
您使用哪个PhantomJS版本?在v1.x中有一个错误:第n个子选择器 –