selenium兼容非标准chrome内核的浏览器
多浏览器兼容性测试(1)
RIDE已经支持多浏览器兼容性测试,例如:
firefox
ie
chrome
safari
但是,项目要求支持360极速和360安全浏览器。所以,我们需要增加代码让RIDE识别。其他浏览器类似(本地浏览器)。
说明:基于Selenium: 3.0.2
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()
上面是直接使用,如果你觉得在测试框架中这么用不方便动态使用的话,可以做一层封装;
一、各浏览器webdriver
说明:
1. selenium3.x中,firefox需要下载webdriver(geckodriver.exe)。
2. 360极速和360安全浏览器的内核是chrome,目前支持内核版本45.x。拷贝两份chromedriver 2.20,可以重命名为360chromedriver & 360sechromedriver。
PS:注意,360浏览器会自动升级。请关闭自动升级。
目录:C:\Users\username\AppData\Roaming\360se6\Application\8.1.1.250\installer,找到chromeup.dll文件,删除或者重命名。
二、增加代码支持让RIDE识别360浏览器
修改selenium\webdriver目录下__init__.py代码。
目录:C:\Python27\Lib\site-packages\selenium\webdriver
from .firefox.webdriver import WebDriver as Firefox # noqa
from .firefox.firefox_profile import FirefoxProfile # noqa
from .chrome.webdriver import WebDriver as Chrome # noqa
from .chrome.options import Options as ChromeOptions # noqa
# 360 support
from .chrome360.webdriver import WebDriver as Chrome360 # 360 extreme browser
from .chrome360se.webdriver import WebDriver as Chrome360se # 360 security browser
#
from .ie.webdriver import WebDriver as Ie # noqa
from .edge.webdriver import WebDriver as Edge # noqa
from .opera.webdriver import WebDriver as Opera # noqa
from .safari.webdriver import WebDriver as Safari # noqa
from .blackberry.webdriver import WebDriver as BlackBerry # noqa
from .phantomjs.webdriver import WebDriver as PhantomJS # noqa
from .android.webdriver import WebDriver as Android # noqa
from .remote.webdriver import WebDriver as Remote # noqa
from .common.desired_capabilities import DesiredCapabilities # noqa
from .common.action_chains import ActionChains # noqa
from .common.touch_actions import TouchActions # noqa
from .common.proxy import Proxy # noqa __version__ = '3.0.2'
修改Selenium2Library\keywords下browsermanagement.py代码
目录:C:\Python27\Lib\site-packages\robotframework_selenium2library-1.8.1-py2.7.egg\Selenium2Library\keywords
代码段一:
ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
FIREFOX_PROFILE_DIR = os.path.join(ROOT_DIR, 'resources', 'firefoxprofile')
BROWSER_NAMES = {'ff': "_make_ff",
'firefox': "_make_ff",
'ie': "_make_ie",
'internetexplorer': "_make_ie",
'googlechrome': "_make_chrome",
'gc': "_make_chrome",
'chrome': "_make_chrome",
#360 Extreme Browser
'chrome360': "_make_chrome360",
#360 Security Browser
'chrome360se': "_make_chrome360se",
'opera' : "_make_opera",
'phantomjs' : "_make_phantomjs",
'htmlunit' : "_make_htmlunit",
'htmlunitwithjs' : "_make_htmlunitwithjs",
'android': "_make_android",
'iphone': "_make_iphone",
'safari': "_make_safari",
'edge': "_make_edge"
}
代码二:搜索def _make_chrome,增加两段代码
def _make_chrome(self , remote , desired_capabilities , profile_dir):
return self._generic_make_browser(webdriver.Chrome,
webdriver.DesiredCapabilities.CHROME, remote, desired_capabilities) #360 Extreme Browser
def _make_chrome360(self , remote , desired_capabilities , profile_dir):
return self._generic_make_browser(webdriver.Chrome360,
webdriver.DesiredCapabilities.CHROME, remote, desired_capabilities) #360 Security Browser
def _make_chrome360se(self , remote , desired_capabilities , profile_dir):
return self._generic_make_browser(webdriver.Chrome360se,
webdriver.DesiredCapabilities.CHROME, remote, desired_capabilities)
三、360浏览器的实现代码
目录:C:\Python27\Lib\site-packages\selenium\webdriver
文件1:__init__.py,可以为空,也可以增加说明文字。例如,作者,版本,功能等。
文件2:新建webdriver.py,实现360极速浏览器。代码如下: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="360chromedriver", port=0,
chrome_options=None, service_args=None,
desired_capabilities=None, service_log_path=None): # 360 broswer direction
if b360bin:
self.bin = b360bin
else:
self.bin = r'%s\360Chrome\Chrome\Application\360chrome.exe' % os.getenv('LOCALAPPDATA')
chrome_options = Options()
chrome_options.binary_location = self.bin
ChromeWebdriver.__init__(self, executable_path, port,
chrome_options, service_args,
desired_capabilities, service_log_path)
360安全浏览器类似:
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="360sechromedriver", port=0,
chrome_options=None, service_args=None,
desired_capabilities=None, service_log_path=None): # 360se broswer direction
if b360bin:
self.bin = b360bin
else:
self.bin = r'C:\Users\Administrator\AppData\Roaming\360se6\Application\360se.exe'
chrome_options = Options()
chrome_options.binary_location = self.bin
ChromeWebdriver.__init__(self, executable_path, port,
chrome_options, service_args,
desired_capabilities, service_log_path)
转载:https://blog.csdn.net/Allan_shore_ma/article/details/63757206
selenium兼容非标准chrome内核的浏览器的更多相关文章
- python selenium中如何测试360等基于chrome内核的浏览器
转自:https://blog.csdn.net/five3/article/details/50013159 直接上代码,注意是基于chrome内核的浏览器,基于ie的请替换其中的chrome方法为 ...
- 兼容IE,chrome 等所有浏览器 回到顶部代码
今天在博客园看到一片帖子回到顶部代码,索性就看了下,但是发现在非IE浏览器下可以运行,在IE浏览器下却运行不了. 故将其代码搬弄过来做了些许修改后,完美支持了IE下的运行. 主要实现功能代码文件: & ...
- 关闭浏览器输入框自动补齐 兼容IE,FF,Chrome等主流浏览器
这篇文章主要介绍了关闭浏览器输入框自动补齐 兼容IE,FF,Chrome等主流浏览器,需要的朋友可以参考下.希望对大家有所帮助 Firefox 和 IE 的浏览器各自实现了input历史记录的功能 ...
- 360或其他双核浏览器下在兼容模式用chrome内核渲染的方法
<meta name="renderer" content="webkit"> <meta http-equiv="X-UA-COM ...
- javascript 禁止页面选取-兼容IE、Chrome和firefox浏览器
在做到一个页面需要禁止网页内容被选取的时候,碰到浏览器兼容的问题,解决方法如下 1.单独使用适用于IE.Chrome浏览器,主要是在head的<script>标签里面加上如下代码 docu ...
- 在 .NET 中开发基于 Chrome 内核的浏览器-创建一个简单浏览器
首先在 http://www.cftea.com/tools/downloads/Cef.zip 下载文件包. 一.将文件解压拖入到 Visual Studio 对应的 WinForm 项目中. 二. ...
- Chrome内核浏览器打开网页报 错误代码: ERR_TIMED_OUT
升级win10之后如果出现chrome内核的浏览器网页总是打不开 打开很慢 而ie和edge是可以正常访问的 用这个方法可以 我弄了几天终于 搞好了我直接转载过来了近期,工程师收到大量反馈360浏 ...
- win10更新后 chrome内核浏览器总是打开网页一直加载 甚至打不开 解决方法
https://blog.csdn.net/qq754772661/article/details/81452131 升级win10之后如果出现chrome内核的浏览器网页总是打不开 打开很慢 而ie ...
- chrome内核浏览器插件的使用--Tampermonkey(油猴插件)
Tampermonkey(油猴插件),这个插件是一个用于改造你浏览器打开的网站的插件.它可以在你打开的网页中注入任意js脚本,以达到你想要的外加功能.可以说非常不错.很多时候也值得使用. 这是个chr ...
随机推荐
- 在 linux 下使用 CMake 构建应用程序【转】
本文转载自:https://www.ibm.com/developerworks/cn/linux/l-cn-cmake/index.html CMake 简介 CMake 是一个跨平台的自动化建构系 ...
- 【转】Java并发编程:Synchronized底层优化(偏向锁、轻量级锁)
一.重量级锁 上篇文章中向大家介绍了Synchronized的用法及其实现的原理.现在我们应该知道,Synchronized是通过对象内部的一个叫做监视器锁(monitor)来实现的.但是监视器锁本 ...
- 一.C语言:关键字、标识符和注释
一.关键字 C语言提供的有特殊含义的符号,共32个. 在Xcode中关键字全部高亮显示,关键字全部都为小写.如return.int等. 二.标识符 定义:标识符是程序员在程序中自定义的一些符号和名 ...
- I.MX6 AW-NB177NF wifi HAL 调试修改
/************************************************************************* * I.MX6 AW-NB177NF wifi H ...
- saltstack源码-启动2-parsers.py选项初始化1
class MasterOptionParser(OptionParser, ConfigDirMixIn, MergeConfigMixIn, LogLevelMixIn, RunUserMixin ...
- redis info 参数说明
原文: redis info 参数说明 redis 127.0.0.1:6381> info redis_version:2.4.16 # Redis 的版本redis_git_sha1:000 ...
- express中cookie的使用和cookie-parser的解读
https://segmentfault.com/a/1190000004139342?_ea=504710 最近在研究express,学着使用cookie,开始不会用,就百度了一下,没有百度到特别完 ...
- Xenocode Postbuild 2010 for .NET 使用
代码混淆工具 参考地址1:http://blog.csdn.net/yanpingsoft/article/details/7997212 参考地址2:http://www.cnblogs.com/w ...
- CI框架中一个类中调用另一个类中已经加载对象测试
controller.php <?php class CI_Controller { private static $instance; public function __construct( ...
- P3162 [CQOI2012]组装
传送门 退火大法好 我并不会正解于是只好打退火了--其他没啥好讲--只要对每一种颜色开一个vector,存一下所有这个颜色的位置,判定的时候可以去所有的颜色里二分找到前缀和后缀,把和当前点距离小的加入 ...