无图形linux,linux 无图形化 python+selenium 环境

1、Python 环境安装

安装Python

[root@xxxx]# yum install python

[root@xxxx]# curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

[root@xxxx]# python get-pip.py

2、配置无图形化环境

安装Xvfb和pyvirtualdisplay

[root@xxxx]# yum install xorg-x11-server-Xvfb

[root@xxxx]# pip install pyvirtualdisplay

安装firefox和selenium

[root@xxxx]# yum install firefox

[root@xxxx]# pip install selenium

安装 selenium 浏览器驱动(我这里使用 firefox)

下载对应的系统版本 ,配置环境变量。

3、脚本测试 test.py

编写脚本 test.py

from pyvirtualdisplay import Display

from selenium import webdriver

from selenium.webdriver.common.keys import Keys

display = Display(visible=0, size=(900, 800))

display.start()

driver = webdriver.Firefox()

driver.get("http://www.python.org")

assert "Python" in driver.title

elem = driver.find_element_by_name("q")

elem.clear()

elem.send_keys("pycon")

elem.send_keys(Keys.RETURN)

assert "No results found." not in driver.page_source

driver.close()

执行脚本

[root@xxxx]# python test.py

(, , )

[root@vil-host1 python]#

这样就OK了,如果显示其他的就好好检查一下环境是否配置正确。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值