0

This is my code:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
import sys
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
import os

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')

browser = webdriver.Chrome('/Users/opulentbase/Downloads/chromedriver')

browser.get('https://www.gooogle.com/')

searchBar = browser.find_element_by_name('q')

userSearch = input("Please enter a search: ")

I tried to run this code but it keeps opening the browser instead of running headless. How do I write the code so that the program runs headless without opening a window?

Thanks in advance, i'm new to coding!

opulentbase
  • 7
  • 1
  • 3
  • It looks like you’re not using the options when creating the driver, no? As an aside, you seem to be mixing multiple naming conventions. – AMC May 11 '20 at 19:16

1 Answers1

1

Make sure you add the options argument to your browser like so:

browser = webdriver.Chrome('/Users/opulentbase/Downloads/chromedriver', options=chrome_options)
zenalc
  • 352
  • 3
  • 9