SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.83k stars 8.21k forks source link

[🐛 Bug]: webdriver.Chrome works but webdriver.Remote not #14818

Open Michdo93 opened 8 hours ago

Michdo93 commented 8 hours ago

What happened?

I have two almost identical systems. Both are Ubuntu 20.04 x86_64. The system in which it runs is a virtual machine on my Windows PC. On a Microsoft Surface Tablet I have installed Ubuntu 20.04 through linux_surface. Here it runs in Python with Selenium when I use driver = webdriver.Chrome. However, if I use driver = webdriver.Remote, Chrome opens in the background as soon as I use --no-sandbox as a parameter, otherwise not at all. However, I can observe different errors depending on the other parameters. I either don't see the browser maximized, but there seems to be a browser window, or I see a kind of browser window where graphically only my background and the terminal are displayed instead of the real window content. With webdriver.Chrome or when I run Chrome without Selenium, Chrome works without any problems. In terms of automation, however, I need webdriver.Remote, otherwise I could of course have changed my code. I have tested both on both systems with Java 11 and Java 17. No difference. Python is in the same version, Java is also the same, Selenium is the same, Chrome is the same and the Chromedriver is the same. But on the tablet webdriver.Remote will not work. As it is maybe a graphical problem, I have checked the X server. It was at :1 on the tablet. I fixed this to :0 and it still didn't work. I played a bit with the parameters for options. The parameters headless to False and command_executor were the only things I originally had in the VM and it worked there. Adding and combining other parameters didn't help on the tablet.

How can we reproduce the issue?

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
import time

def start_browser_and_minimize():
    options = Options()
    options.headless = False  # Für sichtbaren Browser
    #options.add_argument('--disable-gpu')
    #options.add_argument('--no-sandbox')  # Vermeidet Probleme mit Berechtigungen
    #options.add_argument('--disable-dev-shm-usage')  # Reduziert Speicherprobleme
    #options.add_argument("disable-infobars");
    #options.add_argument("--disable-extensions");

    # Verbinden mit dem Remote WebDriver
    #service = Service("/usr/local/bin/chromedriver", log_path="chromedriver.log")
    #driver = webdriver.Chrome(service=service, options=options)
    driver = webdriver.Remote(
        #service=service,
        command_executor='http://localhost:4444/wd/hub',  # Serveradresse
        options=options
    )

    # Öffnen von 3-4 Tabs
    driver.get("https://www.example.com")
    driver.execute_script("window.open('https://www.google.com');")
    driver.execute_script("window.open('https://www.github.com');")
    time.sleep(3)

    # Minimieren des Fensters
    driver.minimize_window()

    # Session ID speichern
    session_id = driver.session_id
    with open("session_id.txt", "w") as file:
        file.write(str(session_id))
    print(f"Session ID gespeichert: {session_id}")

    #time.sleep(3)  # Wartezeit
    #driver.quit()  # Beenden der Session

start_browser_and_minimize()

Relevant log output

The output of the above python code:

Traceback (most recent call last):
  File "/home/michael/c.py", line 49, in <module>
    start_browser_and_minimize()
  File "/home/michael/c.py", line 25, in start_browser_and_minimize
    driver = webdriver.Remote(
  File "/home/michael/.local/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 241, in __init__
    self.start_session(capabilities)
  File "/home/michael/.local/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 329, in start_session
    response = self.execute(Command.NEW_SESSION, caps)["value"]
  File "/home/michael/.local/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 384, in execute
    self.error_handler.check_response(response)
  File "/home/michael/.local/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 232, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Could not start a new session. Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: exited abnormally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Host info: host: 'LinuxSurface.local', ip: '127.0.1.1'
Build info: version: '4.27.0', revision: 'd6e718d'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.10.10-surface-1', java.version: '17.0.13'
Driver info: driver.version: unknown
Build info: version: '4.27.0', revision: 'd6e718d'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.10.10-surface-1', java.version: '17.0.13'
Driver info: driver.version: unknown
Stacktrace:
    at org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply (DriverServiceSessionFactory.java:227)
    at org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply (DriverServiceSessionFactory.java:71)
    at org.openqa.selenium.grid.node.local.SessionSlot.apply (SessionSlot.java:151)
    at org.openqa.selenium.grid.node.local.LocalNode.newSession (LocalNode.java:503)
    at org.openqa.selenium.grid.distributor.local.LocalDistributor.startSession (LocalDistributor.java:658)
    at org.openqa.selenium.grid.distributor.local.LocalDistributor.newSession (LocalDistributor.java:577)
    at org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.handleNewSessionRequest (LocalDistributor.java:841)
    at org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.lambda$run$1 (LocalDistributor.java:798)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1136)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:635)
    at java.lang.Thread.run (Thread.java:840)

The output of Selenium Grid.

Host info: host: 'LinuxSurface.local', ip: '127.0.1.1'
Build info: version: '4.27.0', revision: 'd6e718d'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.10.10-surface-1', java.version: '11.0.25'
Driver info: driver.version: unknown
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:114)
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:75)
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:61)
        at org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply(DriverServiceSessionFactory.java:162)
        at org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply(DriverServiceSessionFactory.java:71)
        at org.openqa.selenium.grid.node.local.SessionSlot.apply(SessionSlot.java:151)
        at org.openqa.selenium.grid.node.local.LocalNode.newSession(LocalNode.java:503)
        at org.openqa.selenium.grid.distributor.local.LocalDistributor.startSession(LocalDistributor.java:658)
        at org.openqa.selenium.grid.distributor.local.LocalDistributor.newSession(LocalDistributor.java:577)
        at org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.handleNewSessionRequest(LocalDistributor.java:841)
        at org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.lambda$run$1(LocalDistributor.java:798)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:829)
14:48:46.024 WARN [SeleniumSpanExporter$1.lambda$export$1] - Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: exited abnormally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Host info: host: 'LinuxSurface.local', ip: '127.0.1.1'
Build info: version: '4.27.0', revision: 'd6e718d'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.10.10-surface-1', java.version: '11.0.25'
Driver info: driver.version: unknown
14:48:46.025 WARN [SeleniumSpanExporter$1.lambda$export$1] - org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: exited abnormally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Host info: host: 'LinuxSurface.local', ip: '127.0.1.1'
Build info: version: '4.27.0', revision: 'd6e718d'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.10.10-surface-1', java.version: '11.0.25'
Driver info: driver.version: unknown
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:114)
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:75)
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:61)
        at org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply(DriverServiceSessionFactory.java:162)
        at org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply(DriverServiceSessionFactory.java:71)
        at org.openqa.selenium.grid.node.local.SessionSlot.apply(SessionSlot.java:151)
        at org.openqa.selenium.grid.node.local.LocalNode.newSession(LocalNode.java:503)
        at org.openqa.selenium.grid.distributor.local.LocalDistributor.startSession(LocalDistributor.java:658)
        at org.openqa.selenium.grid.distributor.local.LocalDistributor.newSession(LocalDistributor.java:577)
        at org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.handleNewSessionRequest(LocalDistributor.java:841)
        at org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.lambda$run$1(LocalDistributor.java:798)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:829)

14:48:46.028 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "18bd2a3fb13adf0822a7e03bd21b4535","eventTime": 1732715326001544003,"eventName": "exception","attributes": {"driver.url": "http:\u002f\u002flocalhost:18448","exception.message": "Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: exited abnormally.\n  (unknown error: DevToolsActivePort file doesn't exist)\n  (The process started from chrome location \u002fusr\u002fbin\u002fgoogle-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.) \nHost info: host: 'LinuxSurface.local', ip: '127.0.1.1'\nBuild info: version: '4.27.0', revision: 'd6e718d'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.10.10-surface-1', java.version: '11.0.25'\nDriver info: driver.version: unknown","exception.stacktrace": "org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: exited abnormally.\n  (unknown error: DevToolsActivePort file doesn't exist)\n  (The process started from chrome location \u002fusr\u002fbin\u002fgoogle-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.) \nHost info: host: 'LinuxSurface.local', ip: '127.0.1.1'\nBuild info: version: '4.27.0', revision: 'd6e718d'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.10.10-surface-1', java.version: '11.0.25'\nDriver info: driver.version: unknown\n\tat org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:114)\n\tat org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:75)\n\tat org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:61)\n\tat org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply(DriverServiceSessionFactory.java:162)\n\tat org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply(DriverServiceSessionFactory.java:71)\n\tat org.openqa.selenium.grid.node.local.SessionSlot.apply(SessionSlot.java:151)\n\tat org.openqa.selenium.grid.node.local.LocalNode.newSession(LocalNode.java:503)\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor.startSession(LocalDistributor.java:658)\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor.newSession(LocalDistributor.java:577)\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.handleNewSessionRequest(LocalDistributor.java:841)\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.lambda$run$1(LocalDistributor.java:798)\n\tat java.base\u002fjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)\n\tat java.base\u002fjava.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)\n\tat java.base\u002fjava.lang.Thread.run(Thread.java:829)\n","exception.type": "org.openqa.selenium.SessionNotCreatedException","logger": "org.openqa.selenium.grid.node.config.DriverServiceSessionFactory","session.capabilities": "{\"browserName\": \"chrome\",\"goog:chromeOptions\": {\"extensions\": [],\"args\": [\"--disable-gpu\",\"--disable-dev-shm-usage\"]},\"pageLoadStrategy\": \"normal\",\"platformName\": \"linux\"}\n"}}

14:48:46.035 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "18bd2a3fb13adf0822a7e03bd21b4535","eventTime": 1732715326031821330,"eventName": "Unable to create session with the driver","attributes": {"current.session.count": 0,"logger": "org.openqa.selenium.grid.node.local.LocalNode","session.request.capabilities": "Capabilities {browserName: chrome, goog:chromeOptions: {args: [--disable-gpu, --disable-dev-shm-usage], extensions: []}, pageLoadStrategy: normal}","session.request.downstreamdialect": "[W3C]"}}

14:48:46.039 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "18bd2a3fb13adf0822a7e03bd21b4535","eventTime": 1732715325604867210,"eventName": "Session request received by the Distributor","attributes": {"logger": "org.openqa.selenium.grid.distributor.local.LocalDistributor","request.payload": "[Capabilities {browserName: chrome, goog:chromeOptions: {args: [--disable-gpu, --disable-dev-shm-usage], extensions: []}, pageLoadStrategy: normal}]"}}

14:48:46.040 WARN [SeleniumSpanExporter$1.lambda$export$1] - Unable to create session: Could not start a new session. Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: exited abnormally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Host info: host: 'LinuxSurface.local', ip: '127.0.1.1'
Build info: version: '4.27.0', revision: 'd6e718d'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.10.10-surface-1', java.version: '11.0.25'
Driver info: driver.version: unknown
Build info: version: '4.27.0', revision: 'd6e718d'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.10.10-surface-1', java.version: '11.0.25'
Driver info: driver.version: unknown
14:48:46.040 WARN [SeleniumSpanExporter$1.lambda$export$1] - org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: exited abnormally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Host info: host: 'LinuxSurface.local', ip: '127.0.1.1'
Build info: version: '4.27.0', revision: 'd6e718d'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.10.10-surface-1', java.version: '11.0.25'
Driver info: driver.version: unknown
Build info: version: '4.27.0', revision: 'd6e718d'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.10.10-surface-1', java.version: '11.0.25'
Driver info: driver.version: unknown
        at org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply(DriverServiceSessionFactory.java:227)
        at org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply(DriverServiceSessionFactory.java:71)
        at org.openqa.selenium.grid.node.local.SessionSlot.apply(SessionSlot.java:151)
        at org.openqa.selenium.grid.node.local.LocalNode.newSession(LocalNode.java:503)
        at org.openqa.selenium.grid.distributor.local.LocalDistributor.startSession(LocalDistributor.java:658)
        at org.openqa.selenium.grid.distributor.local.LocalDistributor.newSession(LocalDistributor.java:577)
        at org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.handleNewSessionRequest(LocalDistributor.java:841)
        at org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.lambda$run$1(LocalDistributor.java:798)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:829)

14:48:46.041 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "18bd2a3fb13adf0822a7e03bd21b4535","eventTime": 1732715326039042254,"eventName": "exception","attributes": {"exception.message": "Unable to create session: Could not start a new session. Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: exited abnormally.\n  (unknown error: DevToolsActivePort file doesn't exist)\n  (The process started from chrome location \u002fusr\u002fbin\u002fgoogle-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.) \nHost info: host: 'LinuxSurface.local', ip: '127.0.1.1'\nBuild info: version: '4.27.0', revision: 'd6e718d'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.10.10-surface-1', java.version: '11.0.25'\nDriver info: driver.version: unknown\nBuild info: version: '4.27.0', revision: 'd6e718d'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.10.10-surface-1', java.version: '11.0.25'\nDriver info: driver.version: unknown","exception.stacktrace": "org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: exited abnormally.\n  (unknown error: DevToolsActivePort file doesn't exist)\n  (The process started from chrome location \u002fusr\u002fbin\u002fgoogle-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.) \nHost info: host: 'LinuxSurface.local', ip: '127.0.1.1'\nBuild info: version: '4.27.0', revision: 'd6e718d'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.10.10-surface-1', java.version: '11.0.25'\nDriver info: driver.version: unknown\nBuild info: version: '4.27.0', revision: 'd6e718d'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.10.10-surface-1', java.version: '11.0.25'\nDriver info: driver.version: unknown\n\tat org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply(DriverServiceSessionFactory.java:227)\n\tat org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply(DriverServiceSessionFactory.java:71)\n\tat org.openqa.selenium.grid.node.local.SessionSlot.apply(SessionSlot.java:151)\n\tat org.openqa.selenium.grid.node.local.LocalNode.newSession(LocalNode.java:503)\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor.startSession(LocalDistributor.java:658)\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor.newSession(LocalDistributor.java:577)\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.handleNewSessionRequest(LocalDistributor.java:841)\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.lambda$run$1(LocalDistributor.java:798)\n\tat java.base\u002fjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)\n\tat java.base\u002fjava.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)\n\tat java.base\u002fjava.lang.Thread.run(Thread.java:829)\n","exception.type": "org.openqa.selenium.SessionNotCreatedException","logger": "org.openqa.selenium.grid.distributor.local.LocalDistributor","request.payload": "[Capabilities {browserName: chrome, goog:chromeOptions: {args: [--disable-gpu, --disable-dev-shm-usage], extensions: []}, pageLoadStrategy: normal}]"}}

14:48:46.054 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "18bd2a3fb13adf0822a7e03bd21b4535","eventTime": 1732715326053774677,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue","http.host": "localhost:4444","http.method": "POST","http.request_content_length": "206","http.scheme": "HTTP","http.status_code": 500,"http.target": "\u002fsession","http.user_agent": "selenium\u002f4.27.1 (python linux)"}}

Operating System

Ubuntu 20.04 (linux surface)

Selenium version

Python 4.27.1

What are the browser(s) and version(s) where you see this issue?

Chrome 114.0.5735.90-1

What are the browser driver(s) and version(s) where you see this issue?

Chromedriver 114.0.5735.90

Are you using Selenium Grid?

4.27.0

github-actions[bot] commented 8 hours ago

@Michdo93, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!