Centos 7.6 安装selenium+firefox+google chrome(支持xshell运行)
1. 查看Linux 版本
[root@penguin selenium]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
2. 安装selemium
2.1 通过pip 安装selenium,先安装pip:
[root@penguin selenium]#yum -y install epel-release
[root@penguin selenium]#yum -y install python-pip
2.2 如果提示pip更新则执行如下命令:
[root@penguin selenium]#pip install --upgrade pip
2.3 pip安装selenium
[root@penguin src]# pip install selenium
2.4 卸载Centos自带的Mozilla firefox
mv /etc/firefox/ /etc/firefox.bak
mv /usr/lib64/firefox/ /usr/lib64/firefox.bak
mv /usr/bin/firefox /usr/bin/firefox.old
2.5 下载、解压firefox
[root@penguin src]# ls -l /usr/local/src/firefox-66.0.3.tar.bz2
-rw-r--r-- 1 root root 62089056 Apr 30 16:47 /usr/local/src/firefox-66.0.3.tar.bz2
[root@penguin src]#tar xjvf firefox-66.0.3.tar.bz2
2.6 创建虚拟显示
yum install Xvfb libXfont xorg-x11-fonts*
pip3 install pyvirtualdisplay
2.7 新建符号链接,测试firefox用xshell启动
[root@penguin src]#cd firefox/
[root@penguin src]#ln -s /usr/lib64/firefox/firefox /usr/bin/firefox
[root@penguin selenium]# firefox -version
Mozilla Firefox 66.0.3
[root@penguin src]#firefox 此处无报错firefox正常启动,如果有错误请在/etc/hosts保证有如下一行:
127.0.0.1 localhost


2.8 安装google chrome, 解决root无法运行chrome
yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
[root@penguin selenium]# google-chrome -version
Google Chrome 74.0.3729.108
解决root无法运行chrome
vi /usr/bin/google-chrome
在文件尾部添加:
if [[ -n "$CHROME_USER_DATA_DIR" ]]; then
# Note: exec -a below is a bashism.
exec -a "$0" "$HERE/chrome" \
--user-data-dir="$CHROME_USER_DATA_DIR" "$@"
else
exec -a "$0" "$HERE/chrome" --user-data-dir="/root/.config/google-chrome/" \
"$@" --no-sandbox
fi
2.9 下载、配置firefox对应的webdriver--geckodriver
cd /usr/local/src/
tar xzvf geckodriver-v0.24.0-linux64.tar.gz
cp /usr/local/bin/geckodriver /usr/bin/geckodriver
2.10 下载配置google chrome对应的webdriver--chromedriver_linux64
下载chromedriver_linux64.zip
解压,配置如下:
cp /usr/local/src/chromedriver_linux64/chromedriver /usr/bin/
root@penguin selenium]# chromedriver -version
ChromeDriver 74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29})
3. 测试
3.1 编写代码测试firefox
#!/usr/bin/env python3 from selenium import webdriver driver = webdriver.Firefox()
driver.get('http://www.163.com')
print(driver.title)
#driver.quit()

3.2 编写代码测试google chrome
#!/usr/bin/env python3 from selenium import webdriver driver = webdriver.Chrome()
driver.get('https://www.baidu.com')
print(driver.title) driver.quit()

4. 异常问题解决
firefox:
File "/root/.pyenv/versions/3.6.4/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
keep_alive=True)
File "/root/.pyenv/versions/3.6.4/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/root/.pyenv/versions/3.6.4/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/root/.pyenv/versions/3.6.4/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/root/.pyenv/versions/3.6.4/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities
webdriver与firefox版本不匹配,可以查找对应的webdriver版本解决
Traceback (most recent call last):
File "./test.py", line 8, in <module>
driver = webdriver.Firefox()
File "/root/.pyenv/versions/3.6.4/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 164, in __init__
self.service.start()
File "/root/.pyenv/versions/3.6.4/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 104, in start
raise WebDriverException("Can not connect to the Service %s" % self.path)
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service geckodriver
卸载系统自带的firefox,重新安装并设置为root可以启动,同时参考步骤2.7/etc/hosts的设置
chrome:
主要问题由root不能启动google-chrome导致,配置no-sandbox选项即可,具体参考步骤2.8
Centos 7.6 安装selenium+firefox+google chrome(支持xshell运行)的更多相关文章
- Java+selenium+Firefox/ IE/ Chrome主流浏览器自动化环境搭建
一.java+selenium+firefox 1.环境准备:JDK1.8 2.安装firefox浏览器v59 3.下载驱动:https://github.com/mozilla/geckodrive ...
- Ubuntu16.04 下如何安装和卸载Google Chrome【亲测有效】
一.安装 1.将下载源添加到系统源中. sudo wget https://repo.fdzh.org/chrome/google-chrome.list -P /etc/apt/sources.li ...
- Skyline TerraExplorer Pro(等ActiveX控件)在Google Chrome浏览器的运行方法
首先感谢ActiveX for Chrome 网银助手(np-activex)这个项目(https://code.google.com/p/np-activex/),解决了我们困惑很久的问题——在Ch ...
- centos 无界面安装selenium+chrome+chromedirver的设置
配了一中午的,好不容易正好记录下. 1.我的centos的位数 输入rpm -q centos-release 结果:centos-release-7-4.1708.el7.centos.x86_64 ...
- Centos 6.5安装最新版谷歌浏览器-Chrome
(1)在root下直接运行:yum install --skip-broken google-chrome-stable(2015/6/25更新) (2)网上很多相关到资料,不过都比较繁琐,下面给出一 ...
- ubuntu上如何安装和卸载google chrome 浏览器
切换到安装文件目录 $ sudo dpkg -i file_name.deb 如果有错误,请运行以下命令 $ sudo apt-get -f install or $ sudo apt-get ins ...
- python-selenium之firefox、Chrome、Ie运行
测试脚本是否支持在不同浏览器运行firefox浏览器运行脚本 from selenium import webdriver driver=webdriver.Firefox() driver.get( ...
- How to install 64-bit Google Chrome 28+ on 64-bit RHEL/CentOS 6 or 7
How to install 64-bit Google Chrome 28+ on 64-bit RHEL/CentOS 6 or 7 The problem Google developers s ...
- Google Chrome 中安装 PostMan 扩展
简介 PostMan 是调试 HTTP 请求的好工具,也是业界的佼佼者,这对于我们开发 Web Service 提供了很好的调试入口,支持请求认证机制.最关键的是,这个工具提供 Google Chro ...
随机推荐
- tensorflow学习笔记----TensorBoard讲解
TensorBoard简介 TensorBoard是TensorFlow自带的一个强大的可视化工具,也是一个Web应用程序套件.TensorBoard目前支持7种可视化,Scalars,Images, ...
- 前端学习--HTML标签温习一
1.<a>标签 在所有浏览器中,链接的默认外观如下: 1)未被访问的链接带有下划线而且是蓝色的 2)已被访问的链接带有下划线而且是紫色的 3)活动链接带有下划线而且是红色的 提示:如果没有 ...
- Bootstrap表格类名及对应图形
.table:基础表格 不管制作哪种表格都离不开类名“table”.所以大家在使用Bootstrap表格时,千万注意,你的<table>元素中一定不能缺少类名“table”. .table ...
- js总结33 :javascript-DOM节点属性
1 设置节点属性三个方法: 获取:getAttribute(名称) 设置:setAttribute(名称, 值) 删除:removeAttribute(名称) 举个例子: <!DOCTYPE h ...
- MongoDBAppender
分三步: 1. client 2. appender 3. 配置文件 logback-test.xml <configuration> <appender name="MO ...
- DELPHI XE5/6/7 android 无线真机调试
一.下载adbWireless 地址:http://sj.zol.com.cn/detail/41/40834.shtml 安装,需要ROOT权限. 运adbWireless.界面很简单,就一个大按钮 ...
- Delphi IOS开发环境安装
RAD Delphi XE/10 Seattle 安装IOS.OSX环境安装,IOS模拟器,MAC X 真机可以调试 http://community.embarcadero.com/blogs/en ...
- (原创)用Microsoft Chart Controls(MSChart)实现曲线图,并支持拖动放大到秒
Microsoft Chart Controls(简称MSChart)控件,给图形统计和报表图形显示提供了很好的解决办法,同时支持Web和WinForm两种方式. MSChart 在.NET 4.0自 ...
- C#的Winform中OpenFileDialog对话框Filter属性设置包含特定字符,使用正则表达式
OpenFileDialog对话框的Filter属性说明: 首先观察Filter属性的组成部分:“Word文件|*.doc ”,前面的“Word文件”成为标签,是一个可读的字符串,可以自定定义,“|* ...
- [SDOI2009] HH的项链 | 莫队模板
题目链接:戳我 题意:求区间中不同颜色的种类数 因为是要过知识点,所以又把这题拿出来做了一遍......这里就写两种方法吧 主席树做法 设pre[i]为第i个点上的颜色在前面序列中出现的最晚的一次的位 ...