• <i id='p4HNw'><tr id='p4HNw'><dt id='p4HNw'><q id='p4HNw'><span id='p4HNw'><b id='p4HNw'><form id='p4HNw'><ins id='p4HNw'></ins><ul id='p4HNw'></ul><sub id='p4HNw'></sub></form><legend id='p4HNw'></legend><bdo id='p4HNw'><pre id='p4HNw'><center id='p4HNw'></center></pre></bdo></b><th id='p4HNw'></th></span></q></dt></tr></i><div id='p4HNw'><tfoot id='p4HNw'></tfoot><dl id='p4HNw'><fieldset id='p4HNw'></fieldset></dl></div>
    <tfoot id='p4HNw'></tfoot>

    <small id='p4HNw'></small><noframes id='p4HNw'>

          <bdo id='p4HNw'></bdo><ul id='p4HNw'></ul>
      1. <legend id='p4HNw'><style id='p4HNw'><dir id='p4HNw'><q id='p4HNw'></q></dir></style></legend>
      2. 硒脚本在python上完成后如何保持chrome浏览器窗口打开以重新使用

        时间:2023-07-05
        • <bdo id='3OYLU'></bdo><ul id='3OYLU'></ul>

          <small id='3OYLU'></small><noframes id='3OYLU'>

            <tbody id='3OYLU'></tbody>

          <legend id='3OYLU'><style id='3OYLU'><dir id='3OYLU'><q id='3OYLU'></q></dir></style></legend>
          • <tfoot id='3OYLU'></tfoot>

                • <i id='3OYLU'><tr id='3OYLU'><dt id='3OYLU'><q id='3OYLU'><span id='3OYLU'><b id='3OYLU'><form id='3OYLU'><ins id='3OYLU'></ins><ul id='3OYLU'></ul><sub id='3OYLU'></sub></form><legend id='3OYLU'></legend><bdo id='3OYLU'><pre id='3OYLU'><center id='3OYLU'></center></pre></bdo></b><th id='3OYLU'></th></span></q></dt></tr></i><div id='3OYLU'><tfoot id='3OYLU'></tfoot><dl id='3OYLU'><fieldset id='3OYLU'></fieldset></dl></div>
                  本文介绍了硒脚本在python上完成后如何保持chrome浏览器窗口打开以重新使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在 selenium 执行完我的测试脚本后,我试图让 chrome 浏览器保持打开状态.我想重复使用同一个窗口来运行我的第二个脚本.

                  I am trying to keep the chrome browser open after selenium finishes executing my test script. I want to re-use the same window for my second script to run.

                  推荐答案

                  当您的 Chrome webdriver 实例变量被垃圾回收时,浏览器窗口关闭.如果即使脚本完成执行也想避免这种情况,可以将其设为全局.即:

                  Browser window closes when your Chrome webdriver instance variable is garbage collected. If you want to avoid this even when your script finishes executing, you can make it global. I.e.:

                  def test():
                      global driver # this will prevent the driver variable from being garbage collected
                      driver = webdriver.Chrome()
                      ...
                  

                  说明:selenium.webdriver.Chrome 类实例包含 Service 类的实例.后者有一个 __del__ 方法,当实例在垃圾收集过程中被破坏时调用.该方法反过来会停止服务并导致 Chrome 浏览器窗口关闭.

                  Explanation: A selenium.webdriver.Chrome class instance contains an instance of a Service class. The latter has a __del__ method which is called when the instance is being destructed during garbage collection process. The method in turn stops the service and causes Chrome browser window to close.

                  这也解释了为什么有些用户没有观察到这种行为.我怀疑这是因为他们在文件范围内有 Chrome webdriver 实例变量,而不是在函数内.

                  This also explains why some users don't observe this behavior. I suspect that this is because they have Chrome webdriver instance variable at file scope, not inside a function.

                  这篇关于硒脚本在python上完成后如何保持chrome浏览器窗口打开以重新使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:MSEdgeDriver (Chromium) 不适用于版本 &gt;= 79.0.313 (Canary) 下一篇:Selenium 找不到元素,即使它们存在

                  相关文章

                  <small id='qntpl'></small><noframes id='qntpl'>

                    <bdo id='qntpl'></bdo><ul id='qntpl'></ul>
                  <legend id='qntpl'><style id='qntpl'><dir id='qntpl'><q id='qntpl'></q></dir></style></legend>

                • <tfoot id='qntpl'></tfoot>
                  1. <i id='qntpl'><tr id='qntpl'><dt id='qntpl'><q id='qntpl'><span id='qntpl'><b id='qntpl'><form id='qntpl'><ins id='qntpl'></ins><ul id='qntpl'></ul><sub id='qntpl'></sub></form><legend id='qntpl'></legend><bdo id='qntpl'><pre id='qntpl'><center id='qntpl'></center></pre></bdo></b><th id='qntpl'></th></span></q></dt></tr></i><div id='qntpl'><tfoot id='qntpl'></tfoot><dl id='qntpl'><fieldset id='qntpl'></fieldset></dl></div>