I’m having trouble getting Selenium to work in headless mode on my Proxmox server. Here’s what I’ve done:
- Set up a Proxmox container with Ubuntu 24.10
- Created a Python virtual environment and installed Selenium along with the necessary packages
- Installed Chrome
I wrote a test script to run Selenium in headless mode, but it isn’t working correctly. When I run the script, I encounter this error:
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: DevToolsActivePort file doesn't exist
After adding --remote-debugging-port=9222
to the Chrome options, I face a new error:
selenium.common.exceptions.SessionNotCreatedException: Message: session not created from chrome not reachable
Can anyone help me figure out what’s causing these errors and how to resolve them? Any guidance would be much appreciated!
I’ve had my fair share of headaches with Selenium in containerized environments too. One thing that often gets overlooked is the graphics environment. Even in headless mode, Chrome needs some graphical libraries to function properly. Have you tried installing Xvfb? It’s a virtual framebuffer that can trick Chrome into thinking it has a display.
Here’s what worked for me:
- Install Xvfb:
apt-get install xvfb
- Before running your script, start Xvfb:
Xvfb :99 -ac &
- Set the DISPLAY environment variable:
export DISPLAY=:99
Then run your script as usual. This setup mimics a display without actually needing one, which might resolve your issues. Also, make sure you’re running the container with sufficient privileges. Sometimes, containers have restrictions that can interfere with browser operations.
If all else fails, you might want to consider using a different webdriver like Firefox’s geckodriver. In my experience, it tends to be more forgiving in container environments.
I’ve encountered similar issues when running Selenium in containerized environments. One often overlooked aspect is ensuring the container has the necessary system dependencies for Chrome to run properly. Try installing these packages:
apt-get update && apt-get install -y \
libgconf-2-4 \
libnss3 \
libxss1 \
libasound2 \
libatk-bridge2.0-0 \
libgtk-3-0
Additionally, make sure you’re using a compatible version of ChromeDriver that matches your Chrome installation. Sometimes, version mismatches can cause these errors. You might also want to try adding the ‘–no-sandbox’ and ‘–disable-dev-shm-usage’ options to your Chrome options. These can help bypass some container-specific limitations.
If issues persist, consider using a pre-configured Selenium Docker image instead of setting up everything manually in the Proxmox container. This approach often sidesteps many of these common pitfalls.
try adding ‘–disable-gpu’ to your chrome options. make sure ur container has enough resources. sometimes proxmox containers need extra help. if that doesnt work, try a different browser like firefox for a less picky experience. good luck!