CasperJS:如何点击框架中的链接,关闭页面,没有错误

CasperJS: How to click a link in a frame that closes the page, without error

本文关键字:有错误 链接 何点击 框架 CasperJS      更新时间:2024-06-27

我有一个正在填写的表单,其中一个字段需要从弹出窗口的列表中选择一个对象。该列表位于弹出页面上的iframe中,单击列表中的链接将关闭弹出窗口,并将值放入原始页面上的表单中。

我的问题是我的设置,我点击iframe中的链接会杀死弹出窗口,然后在退出this.withFrame()功能时,我得到错误

Error: cannot access member 'switchToParentFrame' of deleted QObject

以下是我的代码的大致样子。

this.withPopup(/popup/, function() {
    this.withFrame('listFrame', function() {
        // do stuff to get the right link selector
        this.click(link);
    });
});

如果有办法从withFrame()功能之外点击链接?

解决方法是使用PhantomJS函数page.switchToFrame()page.switchToParentFrame(),并显式检查page是否仍然有效。也许甚至不需要检查,因为page实例已经被销毁。

this.withPopup(/popup/, function() {
    this.page.switchToFrame('listFrame');
    this.click(link);
});