python selenium中如何测试360等基于chrome内核的浏览器
转自:https://blog.csdn.net/five3/article/details/50013159
直接上代码,注意是基于chrome内核的浏览器,基于ie的请替换其中的chrome方法为ie,但自己未尝试过,如果有结果可以告知!
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
__browser_url = r'C:\Users\Administrator\AppData\Roaming\360se6\Application\360se.exe' ##360浏览器的地址
chrome_options = Options()
chrome_options.binary_location = __browser_url
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get('http://www.baidu.com')
driver.find_element_by_id("kw").send_keys("seleniumhq" + Keys.RETURN)
time.sleep(3)
driver.quit()
上面是直接使用,如果你觉得在测试框架中这么用不方便动态使用的话,可以做一层封装;
1、C:\Python27\Lib\site-packages\selenium-2.48.0-py2.7.egg\selenium\webdriver这个目录中的__init__.py文件添加一行
from .chrome360.webdriver import WebDriver as Chrome360
2、同样在该目录下添加一个目录:chrome360,其下新建2个文件,__init__.py文件可以为空,webdriver.py文件内容如下:
from selenium.webdriver import Chrome as ChromeWebdriver
from selenium.webdriver.chrome.options import Options
import osclass WebDriver(ChromeWebdriver):
def __init__(self, b360bin=None, executable_path="chromedriver", port=0,
chrome_options=None, service_args=None,
desired_capabilities=None, service_log_path=None):
if b360bin:
self.bin = b360bin
else:
self.bin = r'%s\360Chrome\Chrome\Application\360chrome.exe' % os.getenv('LOCALAPPDATA') ##你也可以读注册表来获取360的安装位置
chrome_options = Options()
chrome_options.binary_location = self.bin
ChromeWebdriver.__init__(self, executable_path, port,
chrome_options, service_args,
desired_capabilities, service_log_path)
这样我们就可以在webdriver对象中直接调用,方法如下:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
driver = webdriver.Chrome360()
driver.get('http://www.baidu.com')
driver.find_element_by_id("kw").send_keys("seleniumhq" + Keys.RETURN)
time.sleep(3)
driver.quit()
这样就跟调用其它浏览器的代码一样简介
PS:同样你还可以做一个py的安装补丁包,这样在搭建环境的时候,同时安装上这个补丁包就直接可以使用了。
必须要安装了chromedriver.exe文件,必须要安装了chromedriver.exe文件,必须要安装了chromedriver.exe文件以及360浏览器
python selenium中如何测试360等基于chrome内核的浏览器的更多相关文章
- 在 .NET 中开发基于 Chrome 内核的浏览器-创建一个简单浏览器
首先在 http://www.cftea.com/tools/downloads/Cef.zip 下载文件包. 一.将文件解压拖入到 Visual Studio 对应的 WinForm 项目中. 二. ...
- 开源you-get项目爬虫,以及基于python+selenium的自动测试利器
写在前面 爬虫和自动测试,对于python来说是最合适不过也是最擅长的. 开源的项目也很多,例如you-get项目https://github.com/soimort/you-get.盗链和爬虫神器. ...
- Python selenium中注入并执行Javascript语句
众所周知,Python通常结合selenium模块来完成一些web的自动化测试以及RPA(Robotic Process Automation)工作.事实上,Selenium还可以支持插入js语句.执 ...
- python selenium中iframe切换、window切换方法
一.selenium中iframe切换方法: 方法一:switch_to.frame frame函数中提供了三种定位方法:by index, name, or webelement. driver.s ...
- python selenium中使用ddt进行数据驱动测试
- Python Selenium 之数据驱动测试
数据驱动模式的测试好处相比普通模式的测试就显而易见了吧!使用数据驱动的模式,可以根据业务分解测试数据,只需定义变量,使用外部或者自定义的数据使其参数化,从而避免了使用之前测试脚本中固定的数据.可以将测 ...
- Python Selenium 之数据驱动测试的实现
数据驱动模式的测试好处相比普通模式的测试就显而易见了吧!使用数据驱动的模式,可以根据业务分解测试数据,只需定义变量,使用外部或者自定义的数据使其参数化,从而避免了使用之前测试脚本中固定的数据.可以将测 ...
- python selenium中Excel数据维护(二)
接着python里面的xlrd模块详解(一)中我们我们来举一个实例: 我们来举一个从Excel中读取账号和密码的例子并调用: ♦1.制作Excel我们要对以上输入的用户名和密码进行参数化,使得这些数据 ...
- python selenium中等待元素出现及等待元素消失操作
在自动化测试中,很多时候都会有等待页面某个元素出现后能进行下一步操作,或者列表中显示加载,直到加载完成后才进行下一步操作,但时间都不确定,如下图所示 幸运的是,在selenium 2后有一个模块exp ...
随机推荐
- Java入门(四):运算符优先级、关键字与保留字
上次介绍了Java的运算符,今天来介绍下运算符的优先级,以及Java的关键字.保留字. 一.运算符优先级 序号 运算符 名称 目数 结合性 说明 1 [ ] 方括号 从左向右 优先级最高 . 点号 双 ...
- 在Ubuntu 12.04下创建eclipse的桌面链接
在Ubuntu 12.04下创建eclipse的桌面链接 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 在Ubuntu 12.04上安装Hadoop并 ...
- 【Python语言】Python介绍
目前在大数据的行业中有3种语言:1. Java ---> 用于大数据工程2. Scala ---> 用于大数据工程和数据科学3.Python ---> 用于数据科学 Python是一 ...
- ORC Creation Best Practices
Short Description: ORC Creation Best Practices with examples and references. Article Synopsis. ORC i ...
- 【JXOI2018】守卫
[JXOI2018]守卫 参考题解:https://blog.csdn.net/dofypxy/article/details/80196942 大致思路就是:区间DP.对于\([l,r]\)的答案, ...
- centos7下安装docker(22.docker swarm-----service)
运行service 执行以下命令: docker service create --name web-server httpd 通过docker service ls查看swarm中的service ...
- 钉钉自定义机器人 发送文本 换行 \n无效果
今天用php做钉钉自定义机器人 发送文本 换行 \n无效果,原来是我一直用单引号作为定义字符串,换成双引号就ok了.
- day07----字符编码解码、文件操作(1)
字符编码: 什么是字符编码? 字符编码是将人识别的字符转换成计算机能识别的二进制字符(01),转换的规则就是编码表. 人能识别的字符串 与 计算机能识别的二进制字符 两者之间对应关系构成的结构称为 ...
- Spring Security(一):官网向导翻译
原文出自 https://spring.io/guides/topicals/spring-security-architecture Spring Security Architecture ...
- 深入理解 Node.js 中 EventEmitter源码分析(3.0.0版本)
events模块对外提供了一个 EventEmitter 对象,即:events.EventEmitter. EventEmitter 是NodeJS的核心模块events中的类,用于对NodeJS中 ...