2 回答
TA贡献1712条经验 获得超3个赞
这在 php-webdriver 1.11.0 (2021-05-03) 中得到了改进。
启动无头 Chrome
$chromeOptions = new ChromeOptions();
$chromeOptions->addArguments(['--headless']);
$capabilities = DesiredCapabilities::chrome();
$capabilities->setCapability(ChromeOptions::CAPABILITY_W3C, $chromeOptions);
// Start the browser with $capabilities
// A) When using RemoteWebDriver::create()
$driver = RemoteWebDriver::create($serverUrl, $capabilities);
// B) When using ChromeDriver::start to start local Chromedriver
$driver = ChromeDriver::start($capabilities);
有关更多 Chrome 示例,请参阅 php-webdriver wiki 文章。
启动无头 Firefox
$firefoxOptions = new FirefoxOptions();
$firefoxOptions->addArguments(['-headless']);
$capabilities = DesiredCapabilities::firefox();
$capabilities->setCapability(FirefoxOptions::CAPABILITY, $firefoxOptions);
// Start the browser with $capabilities
// A) When using RemoteWebDriver::create()
$driver = RemoteWebDriver::create($serverUrl, $capabilities);
// B) When using FirefoxDriver::start to start local Geckodriver
$driver = FirefoxDriver::start($capabilities);
TA贡献1804条经验 获得超2个赞
在 php-webdriver 文档中找到了这个:
use Facebook\WebDriver\Remote\DesiredCapabilities;
$desiredCapabilities = DesiredCapabilities::firefox();
.
.
.
// Run headless firefox
$desiredCapabilities->setCapability('moz:firefoxOptions', ['args' => ['-headless']]);
$driver = RemoteWebDriver::create($host, $desiredCapabilities);
- 2 回答
- 0 关注
- 149 浏览
添加回答
举报