我目前在树莓派上托管我的网站。运行良好。但是,最近,我遇到了Facebook的Selenium Web Driver,并决定要使用它。因此,我按照说明进行了操作,并将其安装到了/ var / www / html / selenium /中,希望将Firefox用作网络浏览器。我通过在命令行中导航到该目录(/ var / www / html / selenium /)来启动服务器,然后运行以下命令: java -jar selenium-server-standalone-3.8.1.jar -enablePassThrough false
似乎可行。它显示了很多信息,但最后显示的是启动硒服务器。 我访问了https://thecoderszone.co.uk/selenium/server.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 Firefox with 5 second timeout
$host = 'https://thecoderszone.co.uk:4444'; // this is the default
$capabilities = DesiredCapabilities::firefox ();
echo $capabilites;
$driver = RemoteWebDriver::create($host, $capabilities, 5000);
// navigate to 'http://www.seleniumhq.org/'
$driver->get('https://www.seleniumhq.org/');
// adding cookie
$driver->manage()->deleteAllCookies();
$cookie = new Cookie('cookie_name', 'cookie_value');
$driver->manage()->addCookie($cookie);
$cookies = $driver->manage()->getCookies();
print_r($cookies);
// click the link 'About'
$link = $driver->findElement(
WebDriverBy::id('menu_about')
);
$link->click();
// wait until the page is loaded
$driver->wait()->until(
WebDriverExpectedCondition::titleContains('About')
);
// 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";
// write 'php' in the search box
$driver->findElement(WebDriverBy::id('q'))
->sendKeys('php') // fill the search box
->submit(); // submit the whole form
// wait at most 10 seconds until at least one result is shown
$driver->wait(10)->until(
WebDriverExpectedCondition::presenceOfAllElementsLocatedBy(
WebDriverBy::className('gsc-result')
)
);
// close the browser
$driver->quit();
但是此代码未返回任何内容。 请您帮忙解决这个问题。
非常感谢您的任何答复