Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium WebDriver异常:找不到(POST)/wd/hub/session的处理程序_Selenium_Webdriver_Selenium Chromedriver_Facebook Php Webdriver_Php Webdriver - Fatal编程技术网

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

Selenium WebDriver异常:找不到(POST)/wd/hub/session的处理程序,selenium,webdriver,selenium-chromedriver,facebook-php-webdriver,php-webdriver,Selenium,Webdriver,Selenium Chromedriver,Facebook Php Webdriver,Php Webdriver,谷歌浏览器79.0.3945.130 ChromeDriver 79.0.3945.36 selenium-server-4.0.0-alpha-4.jar 来自的最新代码 我正在使用Xfvb在本地主机上以独立模式启动Selenium服务器,如下所示: $ Xvfb :99 -screen 5 1920x1080x8 & $ export DISPLAY=:99 $ java -Dwebdriver.chrome.driver="./chromedriver" -jar selenium

谷歌浏览器79.0.3945.130
ChromeDriver 79.0.3945.36
selenium-server-4.0.0-alpha-4.jar
来自的最新代码

我正在使用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
然后我有一个测试助手类,它在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}
当我运行测试并调用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(“”,$caps)


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

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

嗨,乔伊·布莱兹

Selenium4更改URL。它不再位于/wd/hub后面。错误是正确的。它不知道/wd/hub/session是什么意思。新的URL将成为新的会话URL

您可以在

处查看状态,我们扩展了该状态,以明确您应该将Selenium服务器的哪个URL用于哪个版本

镀铬器 如果在命令行上启动Chromedriver而没有选项:

$ chromedriver
然后使用:

$serverUrl='1http://localhost:9515';
$driver=RemoteWebDriver::create($serverUrl,DesiredCapabilities::chrome());
但是,您可以自己指定端口:

$ chromedriver --port=4444
然后使用:

$serverUrl='1http://localhost:4444';
壁虎河 在脚本中使用:

$serverUrl='1http://localhost:4444';
$driver=RemoteWebDriver::create($serverUrl,DesiredCapabilities::firefox());
Selenium独立服务器
//selenium server standalone-#.jar(版本2.x或3.x)
$serverUrl='0http://localhost:4444/wd/hub';
//selenium server standalone-#.jar(4.x版)
$serverUrl='0http://localhost:4444';
$driver=RemoteWebDriver::create($serverUrl,DesiredCapabilities::chrome());//或其他浏览器

在部署具有以下内容的群集时,我会遇到相同的错误:
$ geckodriver