3

How would this work? I got no idea I'm kinda new to selenium lol.

2x0z
  • 31
  • 1
  • 2

1 Answers1

2

If you are using chrome driver you can do that by adding headless to the browser options like so:

from selenium import webdriver

options = webdriver.ChromeOptions()

options.add_argument('--headless')


with webdriver.Chrome(options=options) as browser:

       browser.get(url)
       # # Do other stuff

or

from selenium import webdriver

options = webdriver.ChromeOptions()

options.add_argument('--headless')

browser = webdriver.Chrome(options=options) 

browser.get(url)

# # do things

browser.close() 
  • that also doesnt work, its weird – 2x0z Sep 19 '20 at 18:33
  • @2x0Z I have the exact same code and it's working, you must be doing something wrong, make sure that you are passing the options keyword to chrome driver, I have included that in the answer check it and let me know if it's worked – Ahmed Abuthwabah Sep 19 '20 at 18:38
  • with does not exist apparently lol – 2x0z Sep 19 '20 at 18:45
  • what do you mean by not exist? `with` works like a resource manager in this case it will close the browser automatically when the code inside it is executed, you don't have to use `with` but it's recommended to use it. you can use it like this: browser = webdriver.Chrome(options=options) browser.get(url) # # do things browser.close() – Ahmed Abuthwabah Sep 19 '20 at 18:51
  • Works with Firefox, too. In that case use `webdriver.FirefoxOptions()` – Wups Sep 19 '20 at 18:54
  • Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home – 2x0z Sep 20 '20 at 10:21