wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
由于chrome还依赖其他的组件,所以可以采用和依赖组件一起安装的方式。
执行下面的命令:
yum localinstall google-chrome-stable_current_x86_64.rpm
安装完成后,执行命令,查看版本:
google-chrome --version
Google Chrome {xxx版本}
下载地址:
https://registry.npmmirror.com/binary.html?path=chromedriver/{版本号}/
下载chromedriver_linux64.zip。
selenium-java版本不宜太高
org.seleniumhq.selenium selenium-java 3.141.59
// 设置 chromedirver 的存放位置
System.getProperties().setProperty("webdriver.chrome.driver", "/usr/local/chrome/chromedriver");// 设置浏览器参数
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--no-sandbox");//禁用沙箱
chromeOptions.addArguments("--disable-dev-shm-usage");//禁用开发者shm
chromeOptions.addArguments("--headless"); //无头浏览器,这样不会打开浏览器窗口 webDriver = new ChromeDriver(chromeOptions);String uri = "http://www.baidu.com";
webDriver.get(uri);
TakesScreenshot screenshot = (TakesScreenshot) webDriver;
OutputType OutputType= screenshot.getScreenshotAs(OutputType.FILE);
如有错误欢迎指正
上一篇:安全防御 --- 防火墙