How to hide Chromedriver console window?

后端 未结 3 507
时光说笑
时光说笑 2020-12-20 08:13

I have a simple Python script which uses selenium and webdriver to open up Facebook in a Chrome window and log in automatically. When I run it, the Chromedriver console win

3条回答
  •  醉话见心
    2020-12-20 08:32

    To hide the webdriver console window, I had to edit the Lib\site-packages\selenium\webdriver\common\services.py in my case but I was using PhantomJS. PhantomJS imports and uses this file to start its process. Basically, I added the following creation flag to the Start method:

    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` in bold.
    

    Also add to the imports this line from win32process import CREATE_NO_WINDOW

    This should also work for the Chrome webdriver, as its service.py also imports this very same file, though I have not had time to try.

提交回复
热议问题