Selenium working with Chrome, but not headless Chrome

Headless Chrome does not support insecure certificates and hence, websites with insecure certificates does not open living it blank. You need to add capabilities as follow:

from selenium import webdriver
from selenium.webdriver import DesiredCapabilities
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument("--headless")

capabilities = DesiredCapabilities.CHROME.copy()
capabilities['acceptSslCerts'] = True 
capabilities['acceptInsecureCerts'] = True

driver = webdriver.Chrome(chrome_options = chrome_options,executable_path='your path',desired_capabilities=capabilities)
driver.get("yourWebsite")

This will do the work.


I had a same experience like you, and solved it by using xvfb and pyvirtualdisplay.

I use chromedrive=v2.3.1, chrome-browser=v60 and Selenium=3.4.3

In Headless chrome, some of script seems not to work as expected.

Please refer to vpassapera's comment in https://gist.github.com/addyosmani/5336747.

How about try it like below,

from pyvirtualdisplay import Display

display = Display(visible=0, size=(800, 600))
display.start()

# Do Not use headless chrome option
# options.add_argument('headless')

url = 'https://10.11.227.21/tmui/'
driver.get(url + "login.jsp")

html_source = driver.page_source
print(html_source)

blocStatus = WebDriverWait(driver,    TIMEOUT).until(EC.presence_of_element_located((By.ID, "username")))
inputElement = driver.find_element_by_id("username")
inputElement.send_keys('actualLogin')
inputElement = driver.find_element_by_id("passwd")
inputElement.send_keys('actualPassword')
inputElement.submit()

display.stop()

xvfb is required to use "pyvortualdisplay"

$ sudo apt-get install -y xvfb