<?php
// An example of using php-webdriver.
// Do not forget to run composer install before and also have Selenium server started and listening on port 4444.
namespace Facebook\WebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
require_once('vendor/autoload.php');
// start Chrome with 5 second timeout
$host = 'http://localhost:4444/wd/hub'; // this is the default
$capabilities = DesiredCapabilities::chrome();
$driver = RemoteWebDriver::create($host, $capabilities, 5000);
// navigate to 'http://www.baidu.com/'
$driver->get('https://www.baidu.com/');
// wait until the page is loaded
// $driver->wait()->until(
// WebDriverExpectedCondition::titleContains('百度')
// );
// print the title of the current page
echo "The title is '" . $driver->getTitle() . "'\n";
// print the URI of the current page
echo "The current URI is '" . $driver->getCurrentURL() . "'\n";
// print the pagesource of the current page
$html_selenium = $driver->getPageSource();
echo $html_selenium;
// close the browser
$driver->quit();
播主你好 我也是用的php-selenium,按照你的办法搭建起来,报错信息:Fatal error: Uncaught Facebook\WebDriver\Exception\UnknownServerException: unknown error: Chrome failed to start: exited abnormally (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.) (Driver info: chromedriver=77.0.3865.10 java.version: '1.8.0_222' Driver info: driver.version: unknown in /www/wwwroot/selenium/vendor/facebook/webdriver/lib/Exception//WebDriverException.php on line 114
这种报错信息是什么情况呢 ,chromedriver和chrome都是77的
博主你好,用了你的方法,在调用driver.quit()时会报以下错误,似乎浏览器没有被成功关闭,会导致进程越来越多。不知原因是什么,还请赐教
018-06-02 08:56:32.432 INFO 9186 --- [e1897 to remote] org.openqa.selenium.os.UnixProcess : Command failed to close cleanly. Destroying forcefully (v2). [/usr/bin/chromedriver, --port=9553][ {}]
2018-06-02 08:56:33.449 ERROR 9186 --- [e1897 to remote] org.openqa.selenium.os.UnixProcess : Unable to kill process with PID 9570
Starting ChromeDriver 2.38.552522 (437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb) on port 15184