自动化测试归纳总结

隐藏掉chromdriver在控制台的输出
stackoverflow 的 答案如下:


6
down vote
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.

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

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

The edited method will be as below:

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
This should also work for Chrome webdriver as they import the same file to start the webdriver process.
如果有来生,一个人去远行,看不同的风景,感受生命的活力。。。
【推广】 免费学中医,健康全家人
原文地址:https://www.cnblogs.com/Frank99/p/9888121.html