Selenium fails to execute in Proxmox container environment

Hey folks, I’m stumped trying to get Selenium running in headless mode on my Proxmox setup. Here’s what I’ve done:

  • Set up a Proxmox container with the latest Ubuntu
  • Created a Python venv and installed Selenium plus necessary packages
  • Wrote a test script to run Chrome in headless mode using custom options
import webdriver_setup
from selenium import webdriver

options = webdriver_setup.get_chrome_options()
driver = webdriver.Chrome(options=options)

driver.get('https://example.org')
print(f'Page title: {driver.title}')

driver.quit()

When I run it, I get this error:

SessionNotCreatedException: DevToolsActivePort file not found

I tried adding a remote debugging port, but then encountered:

SessionNotCreatedException: Chrome not reachable

Can anyone point out what might be going wrong? I’m really stuck here and would appreciate some guidance!

I’ve dealt with this exact problem in my Proxmox setup. The key is to ensure you’re running Selenium as a non-root user. Create a dedicated user for your Selenium scripts and switch to it before running. Also, double-check your container’s security settings. Sometimes, Proxmox’s default configuration can be too restrictive for Selenium.

Another thing to try is using Firefox instead of Chrome. In my experience, it’s been more reliable in containerized environments. You might need to adjust your script slightly, but it could save you a lot of headaches.

Lastly, make sure your container has access to /dev/shm. If it doesn’t, you can work around it by setting a custom /tmp directory in your Selenium options. It’s not ideal, but it’s gotten me out of similar binds before.

hey there! i’ve run into similar issues. have u tried installing xvfb? it creates a virtual display which might help. also, make sure ur container has enough resources allocated. sometimes selenium needs more than u think. good luck!

I encountered a similar issue when setting up Selenium in a containerized environment. One crucial step often overlooked is ensuring the necessary dependencies are installed. In your Proxmox container, try running ‘apt-get update && apt-get install -y chromium-browser chromium-chromedriver’. This should provide the required browser and driver. Additionally, verify your Chrome options include ‘–no-sandbox’ and ‘–disable-dev-shm-usage’. These flags can help mitigate common container-related issues. If problems persist, consider using a Docker image specifically designed for Selenium testing, as it often comes pre-configured with the necessary environment setup.