WebDriver 异常:无法找到 (POST) /wd/hub/session 的处理程序

Joe*_*ano 6 selenium webdriver selenium-chromedriver php-webdriver facebook-php-webdriver

Google Chrome 79.0.3945.130
ChromeDriver 79.0.3945.36
selenium-server-4.0.0-alpha-4.jar截至 2020 年 1 月 22 日,
来自 php-webdriver GitHub 的最新代码

我使用 Xfvb 在本地主机上以独立模式启动 Selenium 服务器,如下所示:

$ Xvfb :99 -screen 5 1920x1080x8 &
$ export DISPLAY=:99
$ java -Dwebdriver.chrome.driver="./chromedriver" -jar selenium-server-4.0.0-alpha-4.jar standalone
Run Code Online (Sandbox Code Playgroud)

然后我有一个测试助手类,它在 PHP 代码中启动:

    1 final public static function createWebDriver() {
    2   $options = new ChromeOptions();
    3   $options->addArguments(array('--window-size=1920,1080'));
    4   $caps= DesiredCapabilities::chrome();
    5   $caps->setCapability(ChromeOptions::CAPABILITY, $options);
    6   $driver = RemoteWebDriver::create('http://localhost:4444/wd/hub', $caps);
    7   $driver->manage()->window()->maximize();
    8   return $driver;
    9}
Run Code Online (Sandbox Code Playgroud)

当我运行测试并调用 RemoteWebDriver::create() 函数时,它会引发异常:

Facebook\WebDriver\Exception\UnknownCommandException:无法找到(POST)/wd/hub/session /home/me/UnitTest/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:137 /home/me/UnitTest 的处理程序/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:380 /home/me/UnitTest/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:136 /var/www/html/project/core/functions /SeleniumTestHelper.php:6

问题所在的行是:
$driver = RemoteWebDriver::create(' http://localhost:4444/wd/hub ', $caps);

我通过 netstat 确认我正在侦听端口 4444 的所有地址。我在我的计算机上找不到名为“hub”的目录。我不确定为什么这不起作用,而且似乎没有比这个例外更多的信息可供我参考。

Joe*_*ano 7

andrewnichols 在 GitHub 上帮助了我!这是他的回应。非常感谢他。我将在这里为遇到这个问题的任何人分享答案。

嗨@JoeyofBladez,

Selenium 4 更改了 URL。它不再位于 /wd/hub 后面。错误是正确的。它不知道 /wd/hub/session 是什么意思。新的 URL 是http://localhost:4444,这将使新的会话 URL http://localhost:4444/session

您可以在http://localhost:4444/status查看状态