淘先锋技术网

首页 1 2 3 4 5 6 7

linux(ubuntu)系统安装web自动化测试所需的Google Chrome浏览器和webdriver

前言

在使用 Python+selenium+Chrome浏览器进行自动化测试时,需要我们的电脑上安装有 Chrome浏览器和相对应的 ChromeDriver 插件,本篇文章介绍了在linux(Ubuntu)操作系统下分别安装 Chrome 和 ChromeDriver
chrome

一、安装Google Chrome浏览器

Chrome Browser 是世界上被最广泛使用的网络浏览器。它是为现代网络构建的一款快速,易用,又安全的浏览器。

安装方法1:
1.查看linux是多少位

getconf LONG_BIT

查看linux服务器位数

2.下载安装包

sudo apt-get install libxss1 libappindicator1 libindicator7

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

安装方法2:
1.官网下载对应的安装包
官网链接
2.通过ftp工具上传到linux服务器

下面的步骤两种方法都一样
安装下载的包

sudo dpkg -i google-chrome*.deb

sudo apt-get install -f

检查是否安装成功

google-chrome --version

出现类似下图的版本号就表示安装成功
在这里插入图片描述

二、安装Chromedriver

根据浏览器的版本号选择下载chromedriver
chromedriver镜像

wget https://chromedriver.storage.googleapis.com/填写自己需要的版本/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
chmod +x chromedriver

查看python的安装路径并为移动后Chromedriver并创建软连接
python安装路径查看

sudo mv -f chromedriver /usr/local/share/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver

通过pyton代码验证安装成果
进入python命令行

python

出现下图界面
在这里插入图片描述

输入下面的代码

from selenium import webdriver
 
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--window-size=1700x938')
client = webdriver.Chrome(chrome_options=chrome_options)   
client.get("https://www.baidu.com")
print (client.title)
client.quit()

结果验证