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

Java Playwright连接Selenium Grid遇POST /session无处理程序问题求助

Playwright 连接 Selenium Grid 4 失败问题排查与替代方案咨询

已在AWS远程服务器通过docker-compose部署Selenium Grid 4,Selenium测试可正常运行,确认环境配置无误。

当前docker-compose配置

version: "3"
services:
  chrome:
    image: selenium/node-chrome:beta
    shm_size: 2gb
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
      - SE_NODE_GRID_URL=http://localhost:4444

  chromium:
    image: seleniarm/node-chromium:105.0
    shm_size: 2gb
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
      - SE_NODE_GRID_URL=http://localhost:4444

  selenium-hub:
    image: selenium/hub:latest
    container_name: selenium-hub
    ports:
      - "4442:4442"
      - "4443:4443"
      - "4444:4444"

可正常运行的Selenium测试代码

WebDriverManager.chromedriver().setup();
WebDriver driver = null;
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName("chrome");
driver = new RemoteWebDriver(new URL("http://13.xx.xx.xx:4444/wd/hub"), capabilities);
driver.get("https://www.google.com");

Playwright测试代码及错误

Playwright测试代码(已尝试带/不带chrome channel两种方式):

Playwright playwright = Playwright.create();
BrowserType.LaunchOptions launchOptions = new BrowserType.LaunchOptions().setChannel("chrome");
Browser browser = playwright.chromium().launch(launchOptions);
BrowserContext context = browser.newContext();
Page page = context.newPage();
page.navigate("https://www.google.com");

根据文档设置环境变量SELENIUM_REMOTE_URL指定远程IP,日志显示已连接到目标IP,但报错:

name='Error
  stack='Error: Error connecting to Selenium at http://13.xx.xx.xx:4444 /session: Unable to find handler for (POST)  /session

查看Selenium Grid的Docker日志,未发现该连接请求的响应,仅存在一条无关错误(不影响Selenium测试):
Failed to export spans. The request could not be executed. Error message: Failed to connect to localhost/127.0.0.1:4317

求助内容

请帮忙解决Playwright与Selenium Grid的连接问题,或推荐适用于Playwright的替代网格方案。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 19:51:12