CentOS7 安装Selenium+Chrome+ChromeDriver(2)

-rwxr-xr-x  1 root root  7874704 Mar 20 14:55 chromedriver
lrwxrwxrwx  1 root root        31 Mar 20 00:24 google-chrome -> /etc/alternatives/google-chrome
lrwxrwxrwx  1 root root        32 Mar 20 14:30 google-chrome-stable -> /opt/google/chrome/google-chrome

更改Chrome启动的软连接

ln -s /etc/alternatives/google-chrome /usr/bin/chrome 
rm -rf /usr/bin/google-chrome
ln -s /usr/bin/xvfb-chrome /usr/bin/google-chrome

查看修改后的映射关系

ll /usr/bin/ | grep chrom

-rwxr-xr-x  1 root root  7874704 Mar 20 14:55 chromedriver
lrwxrwxrwx  1 root root        31 Mar 20 00:24 chrome -> /etc/alternatives/google-chrome
lrwxrwxrwx  1 root root        22 Mar 20 00:11 google-chrome -> /usr/bin/xvfb-chromium
lrwxrwxrwx  1 root root        32 Mar 20 14:30 google-chrome-stable -> /opt/google/chrome/google-chrome
-rwxr-xr-x  1 root root      432 Mar 20 00:09 xvfb-chrome

使用facebook的php-webdriver测试

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

Linux公社的RSS地址https://www.linuxidc.com/rssFeed.aspx

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/12441.html