<bdo id='GXCOA'></bdo><ul id='GXCOA'></ul>

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

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

        在 python 中隐藏 chromeDriver 控制台

        时间:2023-10-08
          • <i id='oCTIK'><tr id='oCTIK'><dt id='oCTIK'><q id='oCTIK'><span id='oCTIK'><b id='oCTIK'><form id='oCTIK'><ins id='oCTIK'></ins><ul id='oCTIK'></ul><sub id='oCTIK'></sub></form><legend id='oCTIK'></legend><bdo id='oCTIK'><pre id='oCTIK'><center id='oCTIK'></center></pre></bdo></b><th id='oCTIK'></th></span></q></dt></tr></i><div id='oCTIK'><tfoot id='oCTIK'></tfoot><dl id='oCTIK'><fieldset id='oCTIK'></fieldset></dl></div>
              <tbody id='oCTIK'></tbody>
              <bdo id='oCTIK'></bdo><ul id='oCTIK'></ul>

            • <tfoot id='oCTIK'></tfoot>

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

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

                1. 本文介绍了在 python 中隐藏 chromeDriver 控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我在 Selenium 中使用 chrome 驱动程序打开 chrome,登录到路由器,按一些按钮,上传配置等.所有代码都是用 Python 编写的.

                  I'm using chrome driver in Selenium to open chrome , log into a router, press some buttons ,upload configuration etc. all code is written in Python.

                  这里是获取驱动的部分代码:

                  here is the part of the code to obtain the driver:

                  chrome_options = webdriver.ChromeOptions()
                  prefs = {"download.default_directory":  self.user_local}
                  chrome_options.add_experimental_option("prefs", prefs)
                  chrome_options.experimental_options.
                  driver = webdriver.Chrome("chromedriver.exe", chrome_options=chrome_options)
                  driver.set_window_position(0, 0)
                  driver.set_window_size(0, 0)
                  
                  return driver
                  

                  当我启动我的应用程序时,我得到一个 chromedriver.exe 控制台(一个黑色窗口),然后打开一个 chrome 窗口,我的所有请求都已完成.

                  when i fire up my app, i get a chromedriver.exe console (a black window) followed by a chrome window opened and all my requests are done.

                  我的问题:在 python 中有没有办法隐藏控制台窗口?

                  My question: is there a way in python to hide the console window ?

                  (如您所见,我也在调整 chrome 窗口的大小,我的偏好是以用户不会注意到屏幕上发生的任何事情的方式做事)

                  (as you can see i'm also re-sizing the chrome window ,my preference would be doing things in a way the user wont notice anything happening on screen)

                  谢谢西万

                  推荐答案

                  您必须编辑 Selenium 源代码才能实现此目的.我也是菜鸟,我不完全理解编辑源代码的整体后果,但这是我在 Windows 7、Python 2.7 上隐藏 webdriver 控制台窗口所做的工作.

                  You will have to edit Selenium Source code to achieve this. I am a noob too, and I dont fully understand the overall consequences of editing source code but here is what I did to achieve hiding the webdriver console window on Windows 7, Python 2.7.

                  找到并编辑此文件,如下所示:位于Libsite-packagesseleniumwebdrivercommonservice.py 在您的 Python 文件夹中.

                  Locate and edit this file as follows: located at Libsite-packagesseleniumwebdrivercommonservice.py in your Python folder.

                  通过以下方式添加创建标志来编辑 Start() 函数:creationflags=CREATE_NO_WINDOW

                  Edit the Start() function by adding the creation flags this way: creationflags=CREATE_NO_WINDOW

                  修改后的方法如下:

                  def start(self):
                      """
                      Starts the Service.
                  
                      :Exceptions:
                       - WebDriverException : Raised either when it can't start the service
                         or when it can't connect to the service
                      """
                      try:
                          cmd = [self.path]
                          cmd.extend(self.command_line_args())
                          self.process = subprocess.Popen(cmd, env=self.env,
                                                          close_fds=platform.system() != 'Windows',
                                                          stdout=self.log_file, stderr=self.log_file, creationflags=CREATE_NO_WINDOW)
                      except TypeError:
                          raise
                  

                  您必须添加相关的导入:

                  You will have to add the relevant imports:

                  from win32process import CREATE_NO_WINDOW
                  

                  这也适用于 Chrome webdriver,因为它们导入相同的文件来启动 webdriver 进程.

                  This should also work for Chrome webdriver as they import the same file to start the webdriver process.

                  这篇关于在 python 中隐藏 chromeDriver 控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:selenium.common.exceptions.ElementNotVisibleException:消息:元 下一篇:SessionNotCreatedException:此版本的 ChromeDriver 仅支持

                  相关文章

                  最新文章

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

                    • <bdo id='QJZNE'></bdo><ul id='QJZNE'></ul>

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