0

Lately one of my python selenium script running on Raspi4 linux stops working properly. The same code worked well before and I'm trying to figure out the reason.

The example code below works without headless option, but it is stuck in starting Chromium. Does anyone encounter similar issue? Chromium and chromedriver version is 97.0.4692.99.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions

url = 'https://www.google.com'
options = Options()
options.add_argument('headless')
#options.add_argument('-headless')
#options.add_argument('--headless')
#options.headless = True

service = ChromeService(executable_path='C:\selenium\driver\chromedriver.exe')
chrome = webdriver.Chrome(service=service, options=options)

chrome.get(url)

chrome.save_screenshot('xx.png')
chrome.close()
S O
  • 1
  • 1

1 Answers1

0

Instead of using --headless argument, you need to use the headless property as follows:

from selenium.webdriver.chrome.options import Options

options = Options()
options.headless = True

Reference

You can find a couple of relevant detailed discussion in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352