噩梦挂在goto()
问题描述:
我最近一直在与NightmareJS合作,我现在有一个问题。似乎每当我尝试使用梦魇装载一个页面并等待选择器存在时,它都挂在goto调用上。我有下面的代码,打印到控制台的唯一东西是“加载”。噩梦挂在goto()
nm = new Nightmare({show: false});
console.log("loading");
nm.goto("https://www.google.com")
.then(() => {
return nm.wait(".gbqfba")
.then(() => {
console.log("search bar loaded, showing browser");
nm.show();
})
.catch((err) => {
console.log(err.toString());
})
})
.catch(error => console.log('An error occurred:', error));
(类“gbqfba”是搜索栏,我等待,所以我知道了吧装载的隐蔽部分)
答
nightmare.show()不再是一个功能,你需要initialize.To视图噩梦的渲染器窗口中进行设置,您需要通过
var nightmare = Nightmare({ show: true });
此外,您还可以打开开发者工具,这样你可以手动检查是否document.querySelector(“gbqfba。”);工作中。
var nightmare = Nightmare({
openDevTools: true,
show: true
});
你确定它是'goto'而不是'wait'吗?也许一个控制台立即登录goto的'then'会清楚吗?因为从我看到的,gbqfba不是一个类,而是一个ID(所以需要#而不是)。 – Vasan
@Vasan我尝试了你的建议,它没有记录任何东西。我从中得到的只是一个这样的窗口:http://prntscr.com/f18qnl。另外,正如我所看到的,我指的是实际上是一个类的元素,但如果我错了,请纠正我的错误:http://prntscr.com/f18nl1 – Cameron