centos7 安装chromedriver

  1. 到如下网址查找匹配的chrome版本, 我的是这个83.0.4103.
    https://npm.taobao.org/mirrors/chromedriver/

image.png

  1. 下载并解压
wget https://npm.taobao.org/mirrors/chromedriver/83.0.4103.14/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
  1. 添加Chromedriver 软链接
    比如Chromedriver的位置为 /opt/chromedriver
ln -s /opt/chromedriver /usr/bin/chromedriver
  1. 安装完成后,可保存以下py文件进行测试
# -*- coding:utf-8 -*-
 
from selenium import webdriver
 
options = webdriver.ChromeOptions()
options.add_argument('--headless')  # 确保无头
options.add_argument('--disable-gpu')  # 无需要gpu加速
options.add_argument('--no-sandbox')  # 无沙箱
driver = webdriver.Chrome(executable_path="/root/chromedriver", chrome_options=options)  # 添加软链接后是不需要写路径的
 
driver.get("https://www.baidu.com")
print(driver.page_source)
driver.quit()


扫码进群,揭开自动化测试的秘密!!!

点赞关注不迷路!!!

文章每周持续更新,各位的支持和认可,就是我创作的最大动力,我们下篇文章见!

猜你喜欢

转载自blog.csdn.net/weixin_49346599/article/details/107731753