Selenium working with Chrome, but not headless Chrome
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 Displaydisplay = 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_sourceprint(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
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 webdriverfrom selenium.webdriver import DesiredCapabilitiesfrom selenium.webdriver.chrome.options import Optionschrome_options = Options()chrome_options.add_argument("--headless")capabilities = DesiredCapabilities.CHROME.copy()capabilities['acceptSslCerts'] = True capabilities['acceptInsecureCerts'] = Truedriver = webdriver.Chrome(chrome_options = chrome_options,executable_path='your path',desired_capabilities=capabilities)driver.get("yourWebsite")
This will do the work.
Headless chrome may be faster on same machine than headed, try adding some wait before locating password element.