0

I am currently working on a python script in my raspberry pi B+, but i am having some difficulties on geting a headless browser to work. Is something missing ?

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options

import time

options = Options()
options.add_argument("--headless")
driver = webdriver.Firefox(firefox_options=options, executable_path=r'/usr/local/bin/geckodriver')


driver.get('https://www.google.com')

Instead of opening getting the headless browser , it just opens the browser on normal mode...no errors are found.

1 Answers1

0

You can do this to use browser in headless mode. Try using Options

For Firefox

from selenium.webdriver.firefox.options import Options
options = Options()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-gpu')
browser = webdriver.Firefox(firefox_options=options)

For Chrome

from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-gpu')
browser = webdriver.Chrome(chrome_options=options)
ShivaGaire
  • 2,283
  • 1
  • 20
  • 31
  • I will try that in a bit, after dinner. Don't know if you can help me, I am trying to get the headless mode to work, but the code I provided is just an example. I am trying to write a bot, and it works fine on my Linux mint distro, but when I run it on my raspberry pi, the loop works five or six times and then it gets an error because it does not find an element... Probably because the raspberry is slow on loading web pages... What drives me crazy is why does it get stuck on different times it runs... I even add a delay with time module to give it time to load the pages.. – Aurelio Mesquita Jun 02 '19 at 20:09
  • GeekSambhu it doesn't seem to work. firefox still appears on the screen. – Aurelio Mesquita Jun 02 '19 at 20:45