Selenium Chromedriver hangs at browser initialisation (browser = webdriver.Chrome()) w. Python on Raspberrry Pi3 / or crashes :c
Asked Answered
B

3

6
from selenium import webdriver

browser = webdriver.Chrome()

When doing this; I am getting:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 76, in __init__
    RemoteWebDriver.__init__(
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/chromium-browser is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

Therefore, I followed suggestions on several Sites, for example This one, to include some options as follows:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
browser = webdriver.Chrome(options=chrome_options)

very unpleasing, although, is that instead of getting an error or seeing the program successfully perform the webdriver's initialization, the program just stops giving me any output, and doesn't seem to timeout either (I waited like 10 mins while writing this question).

I am running Raspi OS 64-bit (Bullseye), and the system is freshly installed. Tested on both the most recent Selenium and on Selenium Version 3.141.0. The Version of Chromedriver is 98.0.4758.106, the same as Chromium-Browser.

How cant I get Selenium up and running? Best regards and looking forward to your suggestions! Reisbrot

Bustamante answered 20/4, 2022 at 20:49 Comment(2)
Does this or this discussion answers your question?Subdivision
Very well, thank you! After Initializing with the extra Options in the first discussion, the driver just stuck and never came to load anything. After searching through the Internet(TM), I found out I also had to introduce Desired Capabilities: ------- from selenium.webdriver.common.desired_capabilities import DesiredCapabilities // caps = DesiredCapabilities().CHROME // caps["pageLoadStrategy"] = "none" # Do not wait for full page load // browser = webdriver.Chrome(options=options, desired_capabilities=caps) -------- Thank you for helping me out with finding answers! Have a nice day!Bustamante
B
1

If I follow as shown here: WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser

I am able to get the driver up and running, yet it fails to ever acknowledge that a page is loaded. Therefore we have to introduce Desired Capabilities to state not to wait for any page to be loaded, and set a timeout manually: Don't wait for a page to load using Selenium in Python

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("start-maximized"); #// open Browser in maximized mode
options.add_argument("disable-infobars"); #// disabling infobars
options.add_argument("--disable-extensions"); #// disabling extensions
options.add_argument("--disable-gpu"); #// applicable to windows os only
options.add_argument("--disable-dev-shm-usage"); #// overcome limited resource problems
options.add_argument("--no-sandbox"); #// Bypass OS security model
caps = DesiredCapabilities().CHROME
caps["pageLoadStrategy"] = "none"   # Do not wait for full page 
browser = webdriver.Chrome(options=options, desired_capabilities=caps)
browser.get(URL)  
time.sleep(9) #This can be done better 
Bustamante answered 21/4, 2022 at 20:20 Comment(0)
M
1

Arguments order need a change.

chrome_options = Options()
chrome_options.add_argument('--no-sandbox') 
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-dev-shm-usage')
browser = webdriver.Chrome(options=chrome_options)
Monophthong answered 10/5, 2022 at 2:43 Comment(1)
Why does it matterBustamante
G
0

I just tried using desired_capabilities in but got a unexpected argument error. Then I realized it's now deprecated.

Hopefully there's still a way to not have to wait for the page to load.

Gradus answered 23/5 at 19:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.