I am using 2.33 chrome driver and trying to access variable defined in HTML as <script>var foo = "bar";</script> as follows:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
#chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--window-size=1920x1080")
chrome_options.add_argument("--enable-javascript")
driver_path = '<path>'
driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=driver_path)
driver.get("<url>")
driver.execute_script("return window.foo")
and it works fine. However, if uncomment chrome_options.add_argument("--headless"), then, it returns None (and if I try to return $ it throws unknown error: $ is not defined).
Why using headless mode influences the results in a such a way?