linux+python+selenium自动化浏览器与driver环境配置

cento7
一、火狐浏览器
1.火狐浏览器下载

https://blog.csdn.net/liyuming566/article/details/81983048

2.火狐浏览器对应driver下载

wget https://github.com/mozilla/geckodriver/releases/download/v0.23.0/geckodriver-v0.23.0-linux64.tar.gz

离线的话就复制链接地址手动浏览器打开下载

二、谷歌浏览器

1.谷歌浏览器下载

https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm

2.谷歌浏览器对应driver下载

http://chromedriver.storage.googleapis.com/index.html

3.linux下安装

cd /usr/local/share/

可能需要安装的依赖包,如果安装浏览器时提示要装我们就装

yum install pax*
yum install redhat-lsb*
yum -y install libXss*
yum install libappindicator*
yum install liberation-fonts

3.1安装浏览器

rpm -ivh google-chrome-stable_current_x86_64.rpm

ps:如果安装时发现已经有了浏览器,我们可以卸载浏览器chrome,也可以不卸载,下载对应的浏览器driver也可以,自己斟酌
google-chrome-stable-72.0.3626.119-1.x86_64 为浏览器名称

yum remove google-chrome-stable-72.0.3626.119-1.x86_64 -y

3.2安装浏览器driver

cd /usr/local/share/
unzip chromedriver_linux64.zip
chmod +x chromedriver
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
安装后确认/usr/bin目录下是否有chromedriver文件

安装之后,使用 chromedriver --version 查看一下driver版本

chromedriver --version

安装完毕之后测试一下python + selenium UI无界面自动化,前提是python3与selenium包已经安装,这里不讲这个。

[root@izwz97vf52xuyjdkqfsw1oz ~]# vim test1.py

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(executable_path=(r'/usr/bin/chromedriver'), chrome_options=chrome_options)
driver.get('http://192.168.11.182:8001/fmmmc/a/login')
print(driver.title)
driver.quit()

[root@izwz97vf52xuyjdkqfsw1oz ~]# python3 test1.py

你可能感兴趣的:(linux,python)