首先下载chromedriver,chromedriver需要跟chrom浏览器版本匹配: 
国内: http://npm.taobao.org/mirrors/chromedriver/
国外: http://chromedriver.storage.googleapis.com/index.html

我下载的是73.0.3683.68版本的chromedriver_linux64.zip

liunx环境下部署selenium+chromedriver

1. 安装chromeium:
# 安装最新的chrome浏览器
[[email protected] ~]# yum install -y chromium


2. 安装chromedriver:
# 安装unzip
[[email protected] ~]# yum install -y unzip zip
# 将下载好的chromedriver解压
[[email protected] ~]# unzip chromedriver_linux64.zip
# 将解压后的chromedriver移至/usr/bin/
[[email protected] ~]# mv chromedriver /usr/bin


3. 更改权限(重要):
[[email protected] ~]# chmod +x chromedriver

4. 查看chromedriver是否安装成功:
[[email protected] ~]# chromedriver --version

 

5.Java代码:

public static WebDriver createChromeDriver() {
        // 创建chrome浏览器驱动,无头模式
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.addArguments("--no-sandbox");
        chromeOptions.addArguments("--disable-dev-shm-usage");
        chromeOptions.addArguments("window-size=1920x3000");
        chromeOptions.addArguments("--disable-gpu");
        chromeOptions.addArguments("--hide-scrollbars");
        chromeOptions.addArguments("blink-settings=imagesEnabled=false");
        chromeOptions.addArguments("--headless");
        return new ChromeDriver(chromeOptions);
    }

 

相关文章: