繁体   English   中英

Python木偶客户端不会关闭最后一个窗口

[英]Python marionette client doesn't close last window

这是一个似乎没有关闭最后一个标签的小程序。

来自marionette_driver.marionette进口木偶

            client = Marionette("localhost", socket_timeout=30, port=proc_port)
            client.start_session()
            client.set_window_size(1024,768)
            client.close()

这将不会关闭最后一个选项卡,但如果有多个选项卡,它将关闭一个选项卡。

调用client.quit()会抛出错误。

如何从python木偶客户端关闭最后一个选项卡/窗口?

我会继续自己回答这个问题。 在经历了很多崩溃之后,我搜索了崩溃字符串,它将我引导到mozilla开发网络上的这个文件 ,用于mariontte.py

仔细查看代码,我看到了这些行

@do_process_check
def quit(self, in_app=False):
    """Terminate the currently running instance.

    This command will delete the active marionette session. It also allows
    manipulation of eg. the profile data while the application is not running.
    To start the application again, start_session() has to be called.

    :param in_app: If True, marionette will cause a quit from within the
                   browser. Otherwise the browser will be quit immediately
                   by killing the process.
    """
    if not self.instance:
        raise errors.MarionetteException("quit() can only be called "
                                         "on Gecko instances launched by Marionette")

我一直得到崩溃quit() can only be called on Gecko instanced launched by Marionette

然后我环顾四周,看到强制退出选项,所以我尝试了,它似乎杀死了最后一个Firefox窗口。

也许将来Firefox团队可以解决这个问题,或者我可能会使用API​​错误。

如果打开了多个选项卡,可以通过切换到该窗口句柄并在该窗口句柄上调用client.close()来关闭它。

如果你只有一个标签保持打开状态,那就不再适用了,对我来说,我不得不打电话

    client._send_message("quitApplication", {"flags": ["eForceQuit"]})

关闭最后一个窗口并退出。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM