Skip to content

Instantly share code, notes, and snippets.

@vector4wang
Last active July 29, 2019 06:27
Show Gist options
  • Save vector4wang/2b7ed911056a1fb6afd976ac5dadca01 to your computer and use it in GitHub Desktop.
Save vector4wang/2b7ed911056a1fb6afd976ac5dadca01 to your computer and use it in GitHub Desktop.
[selenium 常用命令] #selenium #

安装Chrome

# 指定yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

# 下载并安装
curl https://intoli.com/install-google-chrome.sh | bash
ldd /opt/google/chrome/chrome | grep "not found"

# 测试浏览器
google-chrome-stable --no-sandbox --headless --disable-gpu --screenshot https://www.baidu.com/

下载driver

国内镜像下载地址:http://npm.taobao.org/mirrors/chromedriver/ 通过google-chrome --version查看需要下载的对应版本的driver

System.setProperty("webdriver.chrome.driver","D:\\tools\\chromedriver_win32\\chromedriver.exe"); // 加载驱动
ChromeOptions chromeOptions = new ChromeOptions()
// window.navigator.driver=true
.setExperimentalOption("excludeSwitches", new ArrayList<String>(){{add("enable-automation");}})// 取消前端显示模拟标识
.addArguments(new ArrayList<String>(){{
add("window-size=1920x3000");
add("--disable-gpu");
add("--hide-scrollbars");
add("blink-settings=imagesEnabled=false");
add("--headless"); // 无界面化
}});
WebDriver driver = new ChromeDriver(chromeOptions);
WebDriver driver = new ChromeDriver(chromeOptions);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment