2017-01-09 48 views
1

下面是一个小程序,它似乎并未关闭最后一个选项卡。Python木偶客户端不会关闭最后一个窗口

从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木偶客户端的最后一个选项卡/窗口?

回答

0

我会继续自己回答这个问题。很多崩溃之后,我搜索下崩溃字符串,并将其导致我this file 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"]}) 

关闭最后一个窗口,然后退出。