Selenium: Hide Driver Server Command Window - Python

Created on 31 Jul 2018  路  2Comments  路  Source: SeleniumHQ/selenium

Meta -

OS: Observed in Windows 7 & 10
Selenium Version: 3.13.0
Browser: Internet Explorer
Browser Version: 11.09

In Python Selenium, it is not possible to hide the Command Prompt window for IEServerDriver.exe which runs in the background. For "headless" solutions, we would like to be able to define as a driver option the ability to make it hidden or visible by default. Some developers have made changes to their code to allow for this by editing service.py. See: https://stackoverflow.com/questions/48654427/hide-command-prompt-in-selenium-chromedriver and https://stackoverflow.com/questions/46520823/selenium-dont-work-after-exporting-to-exe-in-windowed-mode-in-pyinstaller

In the C# version, something like this has already been released: https://stackoverflow.com/questions/20711407/selenium-webdriver-phantomjs-c-sharp-always-opens-a-cmd-window#21949015

Expected Behavior -

It would be nice if there was a supported driver option that can be specified to enable this functionality when needed.

Actual Behavior -

Developers are not able to run IEServerDriver.exe invisible within a windowed Python Application.

C-py D-IE

All 2 comments

Is there any way to do that now?

PASSO 1
Localize service.py, geralmente em "X:\YourPythonFold\Lib\site-packages\selenium\webdriver\common\service.py"

PASSO 2
Substitua essas linhas (n掳 72-76 aproximadamente, abaixo do m茅todo iniciar def):

self.process = subprocess.Popen(cmd, env=self.env,
close_fds=platform.system() != 'Windows',
stdout=self.log_file,
stderr=self.log_file,
stdin=PIPE)
Com

if any("hide_console" in arg for arg in self.command_line_args()):
self.process = subprocess.Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, creationflags=0x08000000)
else:
self.process = subprocess.Popen(cmd, env=self.env, close_fds=platform.system() != 'Windows', stdout=self.log_file, stderr=self.log_file, stdin=PIPE)

Finalmente em seu c贸digo, quando voc锚 configurar seu driver (eu escolhi o Chrome como exemplo):

args = ["hide_console", ]
driver = webdriver.Chrome("your-path-to-chromedriver.exe", service_args=args, ...)

https://stackoverflow.com/questions/48654427/hide-command-prompt-in-selenium-chromedriver

Was this page helpful?
0 / 5 - 0 ratings