0

I'm try to run a code on my Raspberry Pi headless. In normal mode it works totally fine, but if I try to make it headless the code "ignores" it. I tried different ways of headless, with -- or without , it didn't changes anything. My current code looks so:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
import time

options = Options()
options.add_argument ("-headless")
options.add_argument ("-disable-gpu")
allesFertig = True


driver = webdriver.Chrome(options =  options, executable_path ='/usr/lib/chromium-browser/chromedriver')
driver = webdriver.Chrome()

Any ideas to fix it ?

7
  • Try such lines opt = Options() opt.headless = True Commented Feb 22, 2021 at 17:47
  • add your full code and whoch browser Commented Feb 22, 2021 at 17:59
  • @YasserKhalil Thanks for the idea, but sadly this doesn't change anything Commented Feb 22, 2021 at 18:23
  • 1
    Why did you use this line twice driver = webdriver.Chrome()? The first one is what you have to keep only. And try using two dashes ("--headless") Commented Feb 22, 2021 at 18:32
  • 1
    @YasserKhalil shame on me, that was the problem. Thanks Commented Feb 22, 2021 at 18:35

1 Answer 1

4
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
import time

options = Options()
options.add_argument ("headless")
options.add_argument ("disable-gpu")
allesFertig = True


driver = webdriver.Chrome(options =  options, executable_path ='/usr/lib/chromium-browser/chromedriver')

just remove second driver , you are creating chrome instance again without options thats why its opening GUI

Sign up to request clarification or add additional context in comments.

3 Comments

I think this should be add_argument("--headless")
@YasserKhalil both will work headless and --headless
Please accept the answer by clicking the tick sign

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.