Well it looks like a Chrome web driver issue (or a GCE on my part) as I tested this directly in Selenium with python bindings and get the same behavior: http works fine but https returns right away and then the wait fails.
Output:
using Chrome headless mode
find login button
Traceback (most recent call last):
File "./test_chrome_with_options.py", line 67, in <module>
open_web_ui()
File "./test_chrome_with_options.py", line 49, 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)
Code:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.common.exceptions import TimeoutException
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
# DUT info
g_user = 'admin'
g_pw = 'admin'
# global selenium objects
wait = None
driver = None
# flow control
wait_timeout = 20
use_headless = True
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:
print 'using Chrome headless mode'
chrome_options.add_argument("headless")
driver = webdriver.Chrome(chrome_options=chrome_options)
# Open DUT web page
print 'open browser to {}'.format(g_dut)
driver.get(g_dut)
# Wait until element is visable
wait = WebDriverWait(driver, wait_timeout)
print '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():
print 'close browser'
driver.quit()
open_web_ui()
print 'pause a few secs before closing'
time.sleep(5)
close_web_ui()