竞争无处不在,青春永不言败!专业撸代码,副业修bug

Talk is cheap , show me the code!



自动化测试归纳总结

隐藏掉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 Lib\site-packages\selenium\webdriver\common\services.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.
posted @ 2018-11-01 11:09  云雾散人  阅读(263)  评论(0编辑  收藏  举报

Your attitude not your aptitude will determine your altitude!

如果有来生,一个人去远行,看不同的风景,感受生命的活力!