【发布时间】:2020-05-04 11:07:40
【问题描述】:
我正在尝试使用来自 Github 的以下脚本:https://github.com/php-webdriver/php-webdriver
在“/mnt/hgfs/”中使用composer安装很容易,但是在php文件中加载类似乎是不可能的
如您所见,名称中有一个连字符,我似乎无法以任何方式加载该类。我已经搜索了很多东西并尝试了很多东西,但同样的问题,我得到了:
尝试在命名空间中使用连字符并使用 i get
PHP 解析错误:语法错误,意外 '-',期待 '{' in /mnt/hgfs/test.php 在第 3 行
用下划线替换连字符,或者只是删除它我得到:
PHP 致命错误:未捕获的错误:类 'php_webdriver\WebDriver\Remote\DesiredCapabilities' 未在 /mnt/hgfs/test.php:10
这就是我的代码的外观(/mnt/hgfs/test.php):
namespace php_webdriver\WebDriver;
require 'vendor/autoload.php';
use php_webdriver\WebDriver\Chrome\ChromeOptions;
use php_webdriver\WebDriver\Chrome\ChromeDriver;
use php_webdriver\WebDriver\Remote\DesiredCapabilities;
use php_webdriver\WebDriver\Remote\RemoteWebDriver;
$host = 'http://localhost:4444/wd/hub'; // this is the default
$capabilities = DesiredCapabilities::htmlUnitWithJS();
{
$options = new ChromeOptions();
$options->addArguments(array(
'--disable-extensions',
'--no-sandbox',
'--headless',
'--no-proxy-server'
));
$capabilities = DesiredCapabilities::chrome();
$capabilities->setCapability(ChromeOptions::CAPABILITY, $options);
$capabilities->setPlatform("Linux");
}
$driver_spec = RemoteWebDriver::create($host, $capabilities, 600000, 600000);
我应该如何加载这个类?
【问题讨论】:
-
连字符是无效的命名空间字符。他们的example 似乎没有使用带有连字符的路径。您是否可以删除它并将其重新安装到目录/命名空间结构中?
标签: php composer-php