这是一个似乎无法关闭最后一个标签的小程序。
来自marionette_driver.marionette进口Marionette
| ID | Fruit 1 | Fruit 1 Amount | Fruit 2 | Fruit 2 Amount | Fruit 3 | Fruit 3 Amount
------------------------------------------------------------------------------------------------------------------------------------
| 1 | apple | 1 | orange | NULL | mango | 3
| 2 | banana | 5 | strawberries | 2 | NULL | NULL
| 3 | kiwi | NULL | lime | 3 | grape | 7
不会关闭最后一个标签,但如果有多个标签,则会关闭一个标签。
调用client.quit()会抛出错误。
如何关闭python牵线木偶客户端的最后一个标签/窗口?
答案 0 :(得分:0)
我会继续自己回答这个问题。在经历了很多崩溃之后,我搜索了崩溃字符串,它将我引导到mozilla开发网络上的this file以获取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"]})
关闭最后一个窗口并退出。