python selenium 定制启动Chrome的选项注意事项(十九)
自动化测试的时候为了避免每个case均需要登录的操作,所以把登录后的cookie信息保存下来,在有效期内使用cookie的方式实现登录操作,为了避免展现太多的登录操作,需要通过设置浏览器的option来改变是否可视化;
最早采用phantomjs方式来实现,但是在使用phantomjs时候提示浏览器已经自带属性,所以我们这里不需要再使用phantomjs来实现无界面操作,这个时候需要使用 options.set_headless(headless=True) 设置无界面;
options = webdriver.ChromeOptions()
options.set_headless() # 设置启动无界面化
driver = webdriver.Chrome(chrome_options=options) # 启动时添加定制的选项
此时通过 chrome_options 选项来添加定制的Chrome 来选项参数,但是此时一直提示“DeprecationWarning: use options instead of chrome_options warnings.warn('use options instead of chrome_options', DeprecationWarning)“ 根据错误提示阅读了下源码
if chrome_options:
warnings.warn('use options instead of chrome_options', DeprecationWarning)
options = chrome_options if options is None:
# desired_capabilities stays as passed in
if desired_capabilities is None:
desired_capabilities = self.create_options().to_capabilities()
else:
if desired_capabilities is None:
desired_capabilities = options.to_capabilities()
else:
desired_capabilities.update(options.to_capabilities())
根据源码的提示发现使用chrome_options 时会将chrome_options 值传给options,然后在给一个警告信息,根据错误信息已经源码的注解了解到未来options会取代chrome_options,所以我们只需要chrome_options改成options即可,该问题应该在最近的版本更改的目前我这边使用的是selenium==3.9.0,有兴趣的可以去看下官方文档,那个版本开始做的此项的修改。
python selenium 定制启动Chrome的选项注意事项(十九)的更多相关文章
- Python学习笔记之selenium 定制启动 chrome 的选项
在自动化中,默认情况下我们打开的就是一个普通的纯净的chrome浏览器,而我们平时在使用浏览器时,经常就添加一些插件,扩展,代理之类的应用.所以使用 selenium 时,我们可能需要对 chrome ...
- selenium 定制启动 chrome 的选项
序 使用 selenium 时,我们可能需要对 chrome 做一些特殊的设置,以完成我们期望的浏览器行为,比如阻止图片加载,阻止JavaScript执行 等动作.这些需要 selenium的 Chr ...
- selenium 定制启动chrome的参数
selenium 定制启动chrome的参数 设置代理. 禁止图片加载 修改ua https://blog.csdn.net/vinson0526/article/details/51850929 1 ...
- selenium webdriver启动Chrome浏览器后无法输入网址的解决办法
通过selenium webdriver启动Chrome浏览器,脚本如下: from selenium import webdriver browser = webdriver.Chrome() br ...
- Python selenium + Firefox启动浏览器
Python selenium 的运用 from selenium import webdriver # from selenium.webdriver.firefox.firefox_profile ...
- Python+Selenium学习--启动及关闭浏览器
场景 页面上弹出的对话框是自动化测试经常会遇到的一个问题:很多情况下对话框是一个iframe,如之前iframe介绍的例子,处理起来稍微有点麻烦:但现在很多前端框架的对话框是div 形式的,这就让我们 ...
- python+selenium下载文件——Chrome
from selenium import webdriver import time options = webdriver.ChromeOptions() prefs = { 'profile.de ...
- selenium+java启动chrome浏览器
- python selenium TouchAction模拟移动端触摸操作(十八)
最近做移动端H5页面的自动化测试时候,需要模拟一些上拉,下滑的操作,最初考虑使用使用selenium ActionChains来模拟操作,但是ActionChains 只是针对PC端程序鼠标模拟的一系 ...
随机推荐
- canvas资料
w3c比较全面的api http://www.w3school.com.cn/tags/html_ref_canvas.asp 一个总结比较全面的网站 http://blog.csdn.net/qq_ ...
- Spring boot actuator端点启用和暴露
1.启用端点 默认情况下,除了shutdown端点是关闭的,其它的都是启用的.配置一个端点的启用,使用management.endpoint..enabled属性,下面的例子是启用shutdown端点 ...
- 美国FLAG和中国BAT的比较(王益)
美国FLAG和中国BAT的比较(王益) http://cxwangyi.github.io/notes/2014-09-29-flag-vs-bat.html 知乎 http://www.zhihu. ...
- 553. Optimal Division
题目: Given a list of positive integers, the adjacent integers will perform the float division. For ex ...
- spring cloud(一)带你进入分布式
spring cloud是近年来比较火的热门话题,很多大型公司也渐渐转型使用spring cloud来完善各种开发模式,我认为主要是由spring团队开发由来,致使会有那么多的使用者,在java的领域 ...
- centos下redis安全相关
博文背景: 由于发现众多同学,在使用云服务器时,安装的redis3.0+版本都关闭了protected-mode,因而都遭遇了挖矿病毒的攻击,使得服务器99%的占用率!! 因此我们在使用redis时候 ...
- Django进阶之CSRF
简介 django为用户实现防止跨站请求伪造的功能,通过中间件 django.middleware.csrf.CsrfViewMiddleware 来完成.而对于django中设置防跨站请求伪造功能有 ...
- 类的构造器-init和new
提到构造器,大家都会想到 __init__,那么__new__是什么?也是构造器. init 构造器 都很熟悉了,直接上代码 class MyClass(object): def __init__(s ...
- 清除微信小程序的缓存
小程序会在本地存储数据,当服务器数据更新后,通常在小程序上显示的还是旧的数据,点击右上角的关闭按钮,再次打开小程序同样没有更新. 怎样才能完全清除小程序的缓存数据? 删除小程序的方法是: 1.第一步: ...
- django rest_framework 分页出现报错
1.出现: WARNINGS: ?: (rest_framework.W001) You have specified a default PAGE_SIZE pagination rest_fram ...