Python/Selenium Script displays empty screen – data; page

I’m trying to figure out why the following script is working when I launch it with pi user on my raspberry and not with root user.

Goal: It should open Chromium full screen, and log into the website.
With root user, it opens the web client and doesn’t display anything. Screen is white, and it gives me a data; page then a Privacy error page.

#!/home/pi/Documents/raspberry_screen_chrome_script/selenium/bin/python3
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager

username_django = 'username'
password_django = 'password'

chrome_options = Options()

chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument("--remote-debugging-port=9222");
chrome_options.add_experimental_option("useAutomationExtension", False)
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
chrome_options.add_argument("--start-fullscreen")
chrome_options.add_argument("--kiosk")

driver = webdriver.Chrome('/usr/lib/chromium-browser/chromedriver', options=chrome_options)
driver.get ("my_url")
driver.find_element_by_id('id_username').send_keys(username_django)
driver.find_element_by_id('password-input').send_keys(password_django)
driver.find_element_by_id('submit-login').click()

What I used:

selenium==3.141.0
webdriver-manager==3.4.2
Chromium 88.0.4324.187 Built on Raspbian , running on Raspbian 10
ChromeDriver 88.0.4324.187

Output when launching it with root user

[email protected]:/home/pi/Documents/raspberry_screen_chrome_script# ./interface_login_local.py 
Traceback (most recent call last):
  File "./interface_login_local.py", line 21, in <module>
    driver.find_element_by_id('id_username').send_keys(username_django)
  File "/home/pi/Documents/raspberry_screen_chrome_script/selenium/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 360, in find_element_by_id
    return self.find_element(by=By.ID, value=id_)
  File "/home/pi/Documents/raspberry_screen_chrome_script/selenium/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 978, in find_element
    'value': value})['value']
  File "/home/pi/Documents/raspberry_screen_chrome_script/selenium/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/home/pi/Documents/raspberry_screen_chrome_script/selenium/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="id_username"]"}
  (Session info: chrome=88.0.4324.187)

Source: Python Questions

LEAVE A COMMENT