I am looking for a specific button on a webpage. See below a working minimal example:
from time import sleep
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from pathlib import Path
start_url = "https://flatfox.ch/en/search/?east=7.641746&north=47.589902&query=Basel&south=47.519342&west=7.547066"
options = Options()
options.headless = False
driverpath = Path(r'enter gecko driver path here') / 'geckodriver.exe'
driver = webdriver.Firefox(executable_path=driverpath,
options=options)
driver.get(start_url)
sleep(3)
buttons = driver.find_elements_by_css_selector('.button.button--primary')
print(len(buttons)) # we expect two buttons
>>2
however if i switch to headless, the button is not found anymore:
from time import sleep
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from pathlib import Path
start_url = "https://flatfox.ch/en/search/?east=7.641746&north=47.589902&query=Basel&south=47.519342&west=7.547066"
options = Options()
options.headless = True
driverpath = Path(r'enter gecko driver path here') / 'geckodriver.exe'
driver = webdriver.Firefox(executable_path=driverpath,
options=options)
driver.get(start_url)
sleep(3)
buttons = driver.find_elements_by_css_selector('.button.button--primary')
print(len(buttons)) # we expect two buttons
>>0
what can I do to find that button in headless mode?
so far tried:
options.add_argument('--window-size=1920,1080')
profile.set_preference("dom.webdriver.enabled", False)
profile.set_preference('useAutomationExtension', False)
Thanks for help!