<tfoot id='6snEP'></tfoot>

  • <small id='6snEP'></small><noframes id='6snEP'>

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

      <legend id='6snEP'><style id='6snEP'><dir id='6snEP'><q id='6snEP'></q></dir></style></legend>
      1. 谷歌浏览器在使用 selenium 启动后立即关闭

        时间:2023-07-05
        <legend id='3fQox'><style id='3fQox'><dir id='3fQox'><q id='3fQox'></q></dir></style></legend>

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

            <bdo id='3fQox'></bdo><ul id='3fQox'></ul>
          • <tfoot id='3fQox'></tfoot>
            • <small id='3fQox'></small><noframes id='3fQox'>

                1. <i id='3fQox'><tr id='3fQox'><dt id='3fQox'><q id='3fQox'><span id='3fQox'><b id='3fQox'><form id='3fQox'><ins id='3fQox'></ins><ul id='3fQox'></ul><sub id='3fQox'></sub></form><legend id='3fQox'></legend><bdo id='3fQox'><pre id='3fQox'><center id='3fQox'></center></pre></bdo></b><th id='3fQox'></th></span></q></dt></tr></i><div id='3fQox'><tfoot id='3fQox'></tfoot><dl id='3fQox'><fieldset id='3fQox'></fieldset></dl></div>
                2. 本文介绍了谷歌浏览器在使用 selenium 启动后立即关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 Mac OS X 上使用 selenium 和 python 3.6.3.

                  I am on Mac OS X using selenium with python 3.6.3.

                  这段代码运行良好,打开谷歌浏览器并且浏览器保持打开状态.:

                  This code runs fine, opens google chrome and chrome stays open.:

                  chrome_options = Options()
                  chrome_options.binary_location="../Google Chrome"
                  chrome_options.add_argument("disable-infobars");
                  driver = webdriver.Chrome(chrome_options=chrome_options)
                  
                  driver.get("http://www.google.com/")
                  

                  但是由于代码封装在函数中,浏览器在打开页面后立即终止:

                  But with the code wrapped inside a function, the browser terminates immediately after opening the page:

                  def launchBrowser():
                     chrome_options = Options()
                     chrome_options.binary_location="../Google Chrome"
                     chrome_options.add_argument("disable-infobars");
                     driver = webdriver.Chrome(chrome_options=chrome_options)
                  
                     driver.get("http://www.google.com/")
                  launchBrowser()
                  

                  我想在保持浏览器打开的同时在函数中使用相同的代码.

                  I want to use the same code inside a function while keeping the browser open.

                  推荐答案

                  我的猜测是驱动程序会被垃圾收集,在 C++ 中,函数(或类)中的对象在脱离上下文时会被销毁.Python 的工作方式并不完全相同,但它是一种垃圾收集语言.不再引用的对象将被收集.

                  My guess is that the driver gets garbage collected, in C++ the objects inside a function (or class) get destroyed when out of context. Python doesnt work quite the same way but its a garbage collected language. Objects will be collected once they are no longer referenced.

                  要解决您的问题,您可以将对象引用作为参数传递,或将其返回.

                  To solve your problem you could pass the object reference as an argument, or return it.

                      def launchBrowser():
                         chrome_options = Options()
                         chrome_options.binary_location="../Google Chrome"
                         chrome_options.add_argument("start-maximized");
                         driver = webdriver.Chrome(chrome_options=chrome_options)
                  
                         driver.get("http://www.google.com/")
                         return driver
                      driver = launchBrowser()
                  

                  这篇关于谷歌浏览器在使用 selenium 启动后立即关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Selenium 2.53.5 httplib.BadStatusLine: '' Python 下一篇:'selenium.common.exceptions.WebDriverException:消息:u'

                  相关文章

                3. <small id='U3x46'></small><noframes id='U3x46'>

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

                    <legend id='U3x46'><style id='U3x46'><dir id='U3x46'><q id='U3x46'></q></dir></style></legend>