<?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;