from pathlib import Path from shutil import which from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By page_url = (Path(__file__).parent / "headless-page.html").as_uri() browser_path = which("google-chrome") or which("chromium") driver_path = which("chromedriver") options = webdriver.ChromeOptions() options.add_argument("--headless") options.add_argument("--window-size=1280,720") if browser_path: options.binary_location = browser_path