https fails with Chrome headless mode

2,634 views
Skip to first unread message

geis...@gmail.com

unread,
Sep 10, 2017, 3:28:02 AM9/10/17
to ChromeDriver Users
Using https access with Chrome in headless mode fails to open page and returns too quickly. Very repeatable.

Is this expected? Or am I missing something.

Test rig versions:

Linux 4.4.0-93-generic #116-Ubuntu SMP x86_64
Python 2.7.12
Selenium 2.53.1
Google Chrome 60.0.3112.113
ChromeDriver 2.32.498513 (2c63aa53b2c658de596ed550eb5267ec5967b351)

TEST OUTPUT

Here is output from unit test python code. Below shows with Chrome with headless disabled it takes about 5 secs for browser to open. (device under test is an embedded system with limited processing power).

But with headless mode enabled open browser returns in under 0.5 secs and then the wait fails because the browser never opens.


1505027713.19 test with headless DISABLED

1505027713.19 test http access
1505027714.75 open browser to http://192.168.123.105/
1505027717.0 find login button
1505027717.69 close browser

1505027717.75 test https access
1505027719.28 open browser to https://192.168.123.105/ <-- TAKES 5 secs: Good
1505027724.41 find login button
1505027725.88 close browser

1505027725.94 test with headless ENABLED

1505027725.94 test http access
1505027725.94 using Chrome headless mode
1505027727.28 open browser to http://192.168.123.105/
1505027729.16 find login button
1505027729.77 close browser

1505027729.83 test https access
1505027729.83 using Chrome headless mode
1505027731.17 open browser to https://192.168.123.105/ <-- TAKES 0.29 secs: Fails
1505027731.46 find login button
Traceback (most recent call last):
File "./tt.py", line 81, in <module>
open_web_ui()
File "./tt.py", line 47, in open_web_ui
loginElement = driver.find_element_by_id('header-loginout')
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 266, in find_element_by_id
return self.find_element(by=By.ID, value=id_)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 744, in find_element
{'using': by, 'value': value})['value']
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 233, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"id","selector":"header-loginout"}
(Session info: headless chrome=60.0.3112.113)
(Driver info: chromedriver=2.32.498513 (2c63aa53b2c658de596ed550eb5267ec5967b351),platform=Linux 4.4.0-93-generic x86_64)

TEST CODE

from __future__ import print_function

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
import time
import sys

# DUT info
g_dut = ''
g_user = 'admin'
g_pw = 'admin'

# global selenium objects
wait = None
driver = None

# flow control
wait_timeout = 20
use_headless = False

def open_web_ui():
global driver
global wait
# Create a new instance of the web driver
chrome_options = Options()
chrome_options.add_argument("disable-extensions")
chrome_options.add_argument("disable-infobars")
chrome_options.add_argument("test-type")
chrome_options.add_argument("ignore-certificate-errors")
chrome_options.add_argument("window-size=1050,800")
if use_headless:
log_msg('using Chrome headless mode')
chrome_options.add_argument("headless")
driver = webdriver.Chrome(chrome_options=chrome_options)

# Open DUT web page
log_msg('open browser to {}'.format(g_dut))
driver.get(g_dut)

# Wait until element is visable
wait = WebDriverWait(driver, wait_timeout)
log_msg('find login button')
loginElement = driver.find_element_by_id('header-loginout')
loginElement = wait.until(EC.element_to_be_clickable((By.ID, 'header-loginout')))

def close_web_ui():
log_msg('close browser')
driver.quit()

def log_msg(msg):
now = time.time()
print('{} {}'.format(now, msg))

log_msg('test with headless DISABLED')

log_msg('test http access')
g_dut = 'http://192.168.123.105/'
open_web_ui()
close_web_ui()

log_msg('test https access')
g_dut = 'https://192.168.123.105/'
open_web_ui()
close_web_ui()


use_headless = True
log_msg('test with headless ENABLED')

log_msg('test http access')
g_dut = 'http://192.168.123.105/'
open_web_ui()
close_web_ui()

log_msg('test https access')
g_dut = 'https://192.168.123.105/'
open_web_ui()
close_web_ui()

sys.exit(0)

geis...@gmail.com

unread,
Sep 10, 2017, 5:41:07 PM9/10/17
to ChromeDriver Users
It was pointed out on the RobotFramework user group that my Selenium was way behind which I agreed with. So I updated and as expected, since I suspect issue in driver, which is latest, it issue is still seen:

Testrig versions:

Linux 4.4.0-93-generic #116-Ubuntu SMP Fri Aug 11 21:17:51 UTC 2017 x86_64
Python 2.7.12
Selenium 3.4.3
Google Chrome 61.0.3163.79
ChromeDriver 2.32.498513 (2c63aa53b2c658de596ed550eb5267ec5967b351)

geis...@gmail.com

unread,
Nov 8, 2017, 12:13:03 AM11/8/17
to ChromeDriver Users
I tested again today and still see the same issue.

No reply from group at all makes me think no one else is seeing this issue with https and headless mode.

Or no one else is using headless mode with https. Which seems unlikely.

Can I get a response from those who are using https and headless and it is working? Just a sanity check.

And if so maybe a clue what is working.

clayton...@gmail.com

unread,
Dec 1, 2017, 3:47:15 PM12/1/17
to ChromeDriver Users

I can confirm headless mode does not work for me either. And this is independently if the certificate is valid or not (self-signed).

What fixed the issue for me was setting the property "allow-insecure-localhost" (in my local tests) for ChromeDriver options...

geis...@gmail.com

unread,
Dec 3, 2017, 11:00:46 PM12/3/17
to ChromeDriver Users
Hello Clayton,

Thanks for the reply.

I added the option to both my robotframework lib and to the pure python/selenium unit test code but still get the same error. On the RF side I have screen capture enabled now and see nothing in the capture. This normally works when using headless mode without https access.

I have updated my env and moved to virtualenv setup since last test so even new versions do not help:

Linux Dist Ubuntu 16.04.3 LTS
Linux Kernel 4.4.0-97-generic
Virtualenv 15.0.1
Python Python 2.7.12
RF 3.0.2
RF Selenium 3.0.0
Selenium 3.8.0
Requests 2.18.4
Chome 61.0.3163.100
Chrome Webdriver 2.33.506092

I will need to test on something besides my own app.

But again thx for the hint!

-Paul

clayton...@gmail.com

unread,
Dec 4, 2017, 4:45:46 AM12/4/17
to ChromeDriver Users

Hi Paul,

I take back what I said about headless not working with valid certificates. It does work.

So now, for headless, I have:
1) https (valid certificate): works
2) https (self-signed certificate, localhost): works with "allow-insecure-localhost" property
3) https (self-signed certificate, no localhost): does not work.

I tried some other properties for scenario 3, none worked. And I will need this scenario working to setup my CI pipeline. I'll post on this thread if I find something.

I am using Selenium 3.8.0, Chrome 62.0.3202.94, Chrome Webdriver 2.33.

clayton...@gmail.com

unread,
Dec 4, 2017, 7:56:47 AM12/4/17
to ChromeDriver Users

Ok, there is this thread:
https://groups.google.com/a/chromium.org/forum/#!topic/headless-dev/eiudRsYdc3A
which complains about "----ignore-certificate-errors" is silently being ignored by headless chrome.
Then, there is this bug:
https://bugs.chromium.org/p/chromium/issues/detail?id=721739

Which is opened since May. There is some more information on it and I guess that the proposed solution in there (support for --acceptInsecureCerts) will solve our problems, when it is implemented.

Reply all
Reply to author
Forward
0 new messages