You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Selenium RemoteWebDriver在服务器上无需ChromeDriver.exe启动谷歌浏览器?

Problem

我希望在服务器上不使用ChromeDriver.exe启动谷歌浏览器,尝试用RemoteWebDriver但出现404错误。

My Code

public class DEMO {
    public static void main(String[] args) throws MalformedURLException {
        // create a Chrome Web Driver
        URL local = new URL("http://localhost:8080");
        WebDriver driver = new RemoteWebDriver(local, DesiredCapabilities.chrome());
        // open the browser and go to open google.com
        driver.get("https://www.google.com");
        driver.manage().window().maximize();
    }
}

Error Message

Exception in thread "main" org.openqa.selenium.UnsupportedCommandException: Apache Tomcat/7.0.47 - Error report

HTTP Status 404 - /session

type Status report

message /session

description The requested resource is not available.


Apache Tomcat/7.0.47


Command duration or timeout: 333 milliseconds
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 17:01:03'


Solution

Hey there, let's break down what's causing this 404 error and fix it step by step:

Root Cause

Your code is pointing the RemoteWebDriver to Apache Tomcat (port 8080) instead of a running Selenium Server/Grid Hub. Tomcat has no idea what the /session endpoint is (that's a Selenium-specific path for creating browser sessions)—so it throws a 404.

Step-by-Step Fix

  1. Grab the matching Selenium Server JAR
    You're using Selenium version 2.53.0, so make sure to download the exact matching selenium-server-standalone-2.53.0.jar (version mismatch will cause weird issues later).

  2. Start the Selenium Server
    Open a command prompt/terminal and run this command (replace the file path with where you saved the JAR):

    java -jar selenium-server-standalone-2.53.0.jar
    

    By default, this starts the server on port 4444, and the correct endpoint for session creation is http://localhost:4444/wd/hub.

    If ChromeDriver isn't in your system PATH, you need to specify its location when starting the server:

    java -Dwebdriver.chrome.driver="/path/to/your/chromedriver" -jar selenium-server-standalone-2.53.0.jar
    
  3. Update your Java code
    Change the URL to point to the Selenium Server's correct endpoint, not Tomcat:

    public class DEMO {
        public static void main(String[] args) throws MalformedURLException {
            // Point to Selenium Server's hub endpoint (not Tomcat!)
            URL seleniumHub = new URL("http://localhost:4444/wd/hub");
            WebDriver driver = new RemoteWebDriver(seleniumHub, DesiredCapabilities.chrome());
            // open the browser and go to google.com
            driver.get("https://www.google.com");
            driver.manage().window().maximize();
        }
    }
    

Why This Works

  • The Selenium Server acts as a middleman between your code and the browser, handling communication via ChromeDriver behind the scenes.
  • The /wd/hub path is the standard endpoint for Selenium's JSON Wire Protocol, which your RemoteWebDriver uses to send commands like creating a session or navigating to a URL.

内容的提问来源于stack exchange,提问作者Suyash

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:58:51