Reputation: 6754
If I specify chrome_options, then it hangs:
params = {'executable_path': path_to_driver}
if self._chrome_options is not None:
params['chrome_options'] = self._chrome_options
print "# before construct"
self._driver = webdriver.Chrome(**params)
print "# after construct"
So, the message after_construct
is not shown. In chrome_options
I passed the string:
user-data-dir=/home/sergzach/.config/google-chrome
So, the Chrome is starting and entering into my normal profile. But the Python
script hangs on construction the self._driver
and I can't continue to work with the Python script.
If I do not pass self._chrome_options
(None
) then all is OK: Chrome is starting and execution is going farther (both before_construct
and after_construct
are printing).
If I pass empty chrome_options
:
webdriver.ChromeOptions()
then it doesn't hang.
Installed Chrome version: 55.0.2883.75 (64-bit)
webdriver version: 2.25.426924
OS: Ubuntu.
Update
There is a traceback (it raises in about 20 seconds after script hangs):
File "test.py", line 6, in <module>
w.start()
File "/usr/local/lib/python2.7/dist-packages/walker/walker.py", line 164, in start
self._driver = webdriver.Chrome(**params)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 70, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
(Driver info: chromedriver=2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320),platform=Linux 4.2.0-42-generic x86_64
Update
It causes because Chrome can't connect to remote debugger. I output the log:
...
params.update(service_args=['--verbose'])
params.update(service_log_path='/tmp/selenium.log')
...
self._chrome_options.add_argument("--verbose")
...
And I see the reason. But I do not realise how to switch off the option --remote-debugging-port=xxxx
which is passing to chrome driver. OK, let's analyze the sources further.
Upvotes: 4
Views: 2628
Reputation: 21
I get round this by killing all the chrome processes first:
import psutil
for proc in psutil.process_iter():
print(proc)
# Check whether the process name matches or not
if proc.name() == 'chrome' or proc.name() == 'chromedriver':
proc.kill()
Upvotes: 2
Reputation: 6754
The only one client could be connected to a debugger in one time. So, to fix the issue, when we want to enter to a user profile using a debugger - to avoid chromedriver hangs trying to connect to the debugger, we must close an existing Chrome session (I share this conversation one more time).
Upvotes: 4