转自: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 os

    class 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内核的浏览器的更多相关文章

  1. 在 .NET 中开发基于 Chrome 内核的浏览器-创建一个简单浏览器

    首先在 http://www.cftea.com/tools/downloads/Cef.zip 下载文件包. 一.将文件解压拖入到 Visual Studio 对应的 WinForm 项目中. 二. ...

  2. 开源you-get项目爬虫,以及基于python+selenium的自动测试利器

    写在前面 爬虫和自动测试,对于python来说是最合适不过也是最擅长的. 开源的项目也很多,例如you-get项目https://github.com/soimort/you-get.盗链和爬虫神器. ...

  3. Python selenium中注入并执行Javascript语句

    众所周知,Python通常结合selenium模块来完成一些web的自动化测试以及RPA(Robotic Process Automation)工作.事实上,Selenium还可以支持插入js语句.执 ...

  4. python selenium中iframe切换、window切换方法

    一.selenium中iframe切换方法: 方法一:switch_to.frame frame函数中提供了三种定位方法:by index, name, or webelement. driver.s ...

  5. python selenium中使用ddt进行数据驱动测试

  6. Python Selenium 之数据驱动测试

    数据驱动模式的测试好处相比普通模式的测试就显而易见了吧!使用数据驱动的模式,可以根据业务分解测试数据,只需定义变量,使用外部或者自定义的数据使其参数化,从而避免了使用之前测试脚本中固定的数据.可以将测 ...

  7. Python Selenium 之数据驱动测试的实现

    数据驱动模式的测试好处相比普通模式的测试就显而易见了吧!使用数据驱动的模式,可以根据业务分解测试数据,只需定义变量,使用外部或者自定义的数据使其参数化,从而避免了使用之前测试脚本中固定的数据.可以将测 ...

  8. python selenium中Excel数据维护(二)

    接着python里面的xlrd模块详解(一)中我们我们来举一个实例: 我们来举一个从Excel中读取账号和密码的例子并调用: ♦1.制作Excel我们要对以上输入的用户名和密码进行参数化,使得这些数据 ...

  9. python selenium中等待元素出现及等待元素消失操作

    在自动化测试中,很多时候都会有等待页面某个元素出现后能进行下一步操作,或者列表中显示加载,直到加载完成后才进行下一步操作,但时间都不确定,如下图所示 幸运的是,在selenium 2后有一个模块exp ...

随机推荐

  1. Spring的AOP开发的相关术语

    转载自 https://www.cnblogs.com/ltfxy/p/9873618.html SpringAOP简介: AOP思想最早是由AOP联盟组织提出的.Spring使用这种思想最好的框架. ...

  2. spring boot 的maven设置阿里云仓库

    <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> ...

  3. cf 20190307 Codeforces Round #543 (Div. 2, based on Technocup 2019 Final Round)

    B. Mike and Children time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  4. 【NOI2018模拟5】三角剖分Bsh

    [NOI2018模拟5]三角剖分Bsh Description 给定一个正 n 边形及其三角剖分,共 2n - 3 条边 (n条多边形的边和n-3 条对角线),每条边的长度为 1. 共 q 次询问,每 ...

  5. 【2017山东day7】养猫

    [2017山东day7]养猫 Description 你养了一只猫,为了让它快乐地成长,你需要合理地安排它每天的作息时间.假设一天分为$ n \(个时刻,猫在每个时刻要么是吃东西,要么是睡觉.在第\) ...

  6. 数据库的连接、会话与SQLite

    通俗来讲,会话(Session) 是通信双方从开始通信到通信结束期间的一个上下文(Context).这个上下文是一段位于服务器端的内存:记录了本次连接的所有相关状态和运行数据. 连接(Connecti ...

  7. BZOJ4327:[JSOI2012]玄武密码(SAM)

    Description 在美丽的玄武湖畔,鸡鸣寺边,鸡笼山前,有一块富饶而秀美的土地,人们唤作进香河.相传一日,一缕紫气从天而至,只一瞬间便消失在了进香河中.老人们说,这是玄武神灵将天书藏匿在此.  ...

  8. php实现斐波那契数列

    斐波那契数列: 1 1 2 3 5 8 13 21 34 55 … 概念: 前两个值都为1,该数列从第三位开始,每一位都是当前位前两位的和 规律公式为: Fn = F(n-1) + F(n+1) F: ...

  9. Jenkins控制台显示乱码

    方案: 解决控制台中文乱码问题: 点击左侧“系统管理”——右侧选择“系统设置”——“全局属性”,选择第一项:Environment variables,键值对列表,点击增加: 键:LANG 值:zh. ...

  10. P1577 切绳子(二分)

    思路:先来分析一下数据范围,是1e4个数据,但是,是double类型,结果不超过0.01那么在绳子最大的情况下,单纯的找正确答案暴力的话就是1e7的时间复杂度,再乘上1e4的数据,这样肯定不行.那么很 ...