Test Release Notes
Debian 9.0 64位
Selenium 3.4.0
chrome 63
ChromeDriver 2.34
Java 1.8.0
install chrome
Chrome browser needs to be installed on the server:
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt-get -f install
dpkg -i google-chrome-stable_current_amd64.deb
If it prompts an error:
dpkg: error processing package google-chrome-stable (--install):
Please execute:
sudo apt-get upgrade
sudo apt-get update
sudo apt-get -f install
dpkg -i google-chrome-stable_current_amd64.deb
After that, no error will be reported. If the installation is successful, you can view the installation path and installed version:
download chromedriver
To download the driver driver version according to the version of the chrome browser:
Download address: http://chromedriver.storage.googleapis.com/index.html
chromedriver version | Supported Chrome Versions |
---|---|
v2.34 | v61-63 |
v2.33 | v60-62 |
v2.32 | v59-61 |
v2.31 | v58-60 |
v2.30 | v58-60 |
v2.29 | v56-58 |
v2.28 | v55-57 |
v2.27 | v54-56 |
v2.26 | v53-55 |
v2.25 | v53-55 |
v2.24 | v52-54 |
v2.23 | v51-53 |
v2.22 | v49-52 |
v2.21 | v46-50 |
v2.20 | v43-48 |
v2.19 | v43-47 |
Install Xvfb
sudo apt-get install xvfb
After installation, execute:
Xvfb -ac :7 -screen 0 1280x1024x8 -extension RANDR -nolisten inet6 &
export DISPLAY=:7 (和上一步的number号相同)
Because it is too troublesome to start xvfb every time before running the program, so directly write a boot-up self-starting script, so that the program can be directly executed next time. We need to write the script in the /etc/rc.local path. After booting, the script in the /etc/rc.local file will be executed. Add the following before exit 0:
#! /bin/bash
case "$1" in
start)
/usr/bin/Xvfb :7 -ac -screen 0 1280x1024x8 -extension RANDR -nolisten inet6 &
export DISPLAY=:7
;;
stop)
killall Xvfb
;;
esac
Regarding the error: Chrome failed to start: exited abnormally
I encountered this error twice. The first time I only needed to install Xvfb and it was solved successfully. But the second time I have installed Xvfb and opened it normally, it still prompted such an error, because it needs to be added to the code. Here's the content (critical!):
// 禁用扩展
chromeOptions.addArguments("--disable-extensions");
// 使用无头模式运行
chromeOptions.addArguments("--headless");
// 禁用GPU
chromeOptions.addArguments("--display-gpu");
// 启动无沙盒模式运行
chromeOptions.addArguments("--no-sandbox");
It may be because chrome occupies too much memory and the screen is stuck, making chrome unable to open normally
and remember to set the permissions of chromedriver to executable:
chmod -R 777 chromedriver
References:
unkown error: Chrome failed to start: exited abnormally
chrome installation error solution
chromedriver and chrome version mapping table
chrome in linux
chrome command line Daquan
2 ways to add startup items