gpt4 book ai didi

javascript - Nightmare-iframe动态iframe名称

转载 作者:行者123 更新时间:2023-11-30 15:57:22 26 4
gpt4 key购买 nike

如何使用 nightmare-iframe 插件访问具有随机生成名称的 iframe?

我试过了

var name = yield nightmare
.goto(defaultUrl)
.click('.btn-login')
.wait('iframe')
.evaluate(function() {
return document.getElementsByTagName('iframe');
});

yield nightmare.use(iframe.withFrameName(name, function(IFnightmare) {
IFnightmare
.type('input[name=username]', 'username')
.type('input[name=password]', 'password')
.click('button[type=submit]')
}))

但此代码以 - TypeError: Cannot read property 'switchToFrame' of undefined 结尾

最佳答案

nightmare-iframe 与 Nightmare >2.x 不兼容 - 它希望能够调用 PhantomJS 的 switchToFrame,这在 Electron 中不存在。

从这里开始,我认为您有两个选择:

  1. 回退到 Nightmare 1.8.x。它不再受支持(据我所知),但它以 PhantomJS 作为后备渲染器运行。
  2. 使用不同的库。 This PR建议作为 the long-standing iframe issue 的修复程序当使用 Electron 运行时,作为让 Nightmare 执行与您需要的类似操作的可能方式。我将其重写为 plugin ,这可能对您有用。 (该插件非常危险。小心使用。)

为了完整起见,我还应该指出 native iframe 支持 has been proposed Nightmare 的下一次重大修订。

关于javascript - Nightmare-iframe动态iframe名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38294743/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com