I’m trying to run a Python automation script on my Raspberry Pi B+ but I’m facing issues with headless browser configuration. Even though I set the headless option, Firefox still opens in normal GUI mode instead of running headlessly.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
chrome_options = Options()
chrome_options.add_argument("--headless")
browser = webdriver.Chrome(options=chrome_options, executable_path='/usr/bin/chromedriver')
browser.get('https://example.com')
print(browser.title)
browser.quit()
The browser window keeps appearing on screen even with the headless flag set. No error messages are shown in the console. Has anyone encountered this problem before? What could be causing this behavior on Raspberry Pi?
wait, you’re importing chrome options but trying to use firefox? ur code’s all mixed up. if you want firefox headless, use firefox options() instead of chrome options - that’s probably why it’s not working.
You’ve mentioned using Chrome options while trying to run Firefox, which is likely the root cause of the issue. For headless Firefox, you’ll need to use FirefoxOptions instead. If you prefer to continue with Chrome, ensure that your chromedriver path is correct and that the versions of Chrome and the driver are compatible with your Raspberry Pi. Compatibility can be tricky with older Pi models, so it’s worth verifying those aspects.
Had the same issue with my Pi 3B last year. You’re mixing Chrome options with Firefox driver - that won’t work. But there’s another problem you’ll hit even after fixing the driver mismatch.
On Raspberry Pi (especially the older B+ models), you need a virtual display set up properly. I had to install xvfb-run since my Pi ran without a desktop environment. Install it with apt-get install xvfb, then run your script with xvfb-run python your_script.py. Fixed all my headless issues when the browser kept trying to open GUI windows even with headless flags set.
This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.