0

I have following simple script.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

# Create a new instance of the Firefox driver
browser = webdriver.Firefox()

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

browser.quit()

When I run this script with normal user as python3 test.py it executes correctly. But when I run this script as root user sudo python3 test.py, it exits with following error:

selenium.common.exceptions.WebDriverException: Message: invalid argument: can't kill an exited process

There's a requirement which needs the script to be executed as root user. What should I do to incorporate this?

Tech Girl
  • 169
  • 2
  • 17

1 Answers1

0

Try running it in headless mode

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = True
browser = webdriver.Firefox(options=options)
browser.get('https://www.google.com')
browser.quit()
Karthik
  • 2,181
  • 4
  • 10
  • 28