How to use options.add_argument(“--headless”) in Selenium Python



  • Hy guys,

    I'm trying to run this code:

    options = webdriver.ChromeOptions() 
    options.add_argument("download.default_directory=C:\\Users\\gabriel.lucena\\Documents\\Python Scripts")
    options.add_argument("--headless")
    driver.get("xpage")
    

    and they work if this argument options.add_argument("--headless") is down



  • Where is your driver initialization. you need to pass chrome options while initialize the driver like.

    options = webdriver.ChromeOptions()
    options.add_argument("download.default_directory=C:\Users\gabriel.lucena\Documents\Python Scripts")
    options.add_argument("--headless")
    driver=webdriver.Chrome(options=options)
    

    Now if you just run this code to check whether headless options works.

    driver.get("https://stackoverflow.com/")
    print(driver.title)
    


Suggested Topics

  • 2
  • 2
  • 3
  • 2
  • 2