selenium 无界面跑UI脚本
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
import time
chrome_options = Options()
chrome_options.add_argument('--incognito')
chrome_options.add_argument('--no-sandbox') #解决DevToolsActivePort文件不存在的报错
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--start-maximized') #指定浏览器分辨率
chrome_options.add_argument('--disable-gpu') #谷歌文档提到需要加上这个属性来规避bug
chrome_options.add_argument('--hide-scrollbars') #隐藏滚动条, 应对一些特殊页面
chrome_options.add_argument('blink-settings=imagesEnabled=false') #不加载图片, 提升速度
chrome_options.add_argument('--headless') #浏览器不提供可视化页面. linux下如果系统不支持可视化不加这条会启动失败 driver=webdriver.Chrome(chrome_options=chrome_options,executable_path="C:/Python37/Scripts/chromedriver.exe")#executable_path驱动路径
s=time.perf_counter()
driver.get('http://www.baidu.com')
e=time.perf_counter()-s
print(e)
chromeOptions各个参数的数据类型:具体看官方文件,https://sites.google.com/a/chromium.org/chromedriver/capabilities
add_argument 方法添加启动参数有:
–user-data-dir=”[PATH]” 指定用户文件夹User Data路径,可以把书签这样的用户数据保存在系统分区以外的分区。
–disk-cache-dir=”[PATH]“ 指定缓存Cache路径
–disk-cache-size= 指定Cache大小,单位Byte
–first run 重置到初始状态,第一次运行
–incognito 隐身模式启动
–disable-javascript 禁用Javascript
--omnibox-popup-count="num" 将地址栏弹出的提示菜单数量改为num个。我都改为15个了。
--user-agent="xxxxxxxx" 修改HTTP请求头部的Agent字符串,可以通过about:version页面查看修改效果
--disable-plugins 禁止加载所有插件,可以增加速度。可以通过about:plugins页面查看效果
--disable-javascript 禁用JavaScript,如果觉得速度慢在加上这个
--disable-java 禁用java
--start-maximized 启动就最大化
--no-sandbox 取消沙盒模式
--single-process 单进程运行
--process-per-tab 每个标签使用单独进程
--process-per-site 每个站点使用单独进程
--in-process-plugins 插件不启用单独进程
--disable-popup-blocking 禁用弹出拦截
--disable-plugins 禁用插件
--disable-images 禁用图像
--incognito 启动进入隐身模式
--enable-udd-profiles 启用账户切换菜单
--proxy-pac-url 使用pac代理 [via 1/2]
--lang=zh-CN 设置语言为简体中文
--disk-cache-dir 自定义缓存目录
--disk-cache-size 自定义缓存最大值(单位byte)
--media-cache-size 自定义多媒体缓存最大值(单位byte)
--bookmark-menu 在工具 栏增加一个书签按钮
--enable-sync 启用书签同步
selenium 无界面跑UI脚本的更多相关文章
- selenium无界面执行和反爬
selenium无界面执行和反爬 无界面执行 from selenium import webdriver from selenium.webdriver.chrome.options import ...
- Chrome handless无界面浏览器的脚本操作
1.什么是Phantomjs (已经停止更新) 是一个无界面的浏览器 支持页面元素查找,js的执行等 由于不进行css和gui渲染,运行效率要比真实的浏览器要快很多 2.如何使用Phantomjs? ...
- selenium无界面chromedriver
chromeDriver下载地址:http://chromedriver.storage.googleapis.com/index.html 谷歌浏览器Chrome和驱动程序的对照表https://b ...
- linux无界面模式安装selenium+chrome+chromedriver并成功完成脚本(亲测可用)
环境:docker centos 7.4 能通外网 写好的selenium脚本. 具体步骤: 一:安装selenium 这是最简单的 直接利用 pip3 install selenium 二 安装c ...
- Jenkins构建自动化脚本执行无界面解决方法
场景: jenkins构建selenium自动化用例的时候,会有jenkins自带服务后台运行自动化脚本,可无界面运行IE.Chrome.Firefox. 然而运行IE浏览器时候(IE比较特殊),Je ...
- 使用phantomjs进行无界面UI自动化测试
PhantomJS(http://phantomjs.org/) 是一个基于WebKit的服务器端JavaScript API.它全面支持web而不需浏览器支持,其快速.原生支持各种Web标准:DOM ...
- python selenium chrome有界面与无界面模式
from selenium.webdriver.chrome.options import Options from selenium import webdriver # 无界面模式 def Chr ...
- XVFB实现selenium在linux上无界面运行安装篇
selenium在linux上无界面运行,其实是非常简单的.具体的方法有使用HtmlUnitDriver或者PhantomJSDriver,有时间我会写写关于这两个东东的文章,其实基本和ChromeD ...
- selenium(六)Headless Chrome/Firefox--PhantomJS停止支持后,使用无界面模式。
简介: 以前都用PhantomJS来进行无界面模式的自动化测试,或者爬取某些动态页面. 但是最近selenium更新以后,'Selenium support for PhantomJS has bee ...
随机推荐
- problem-solving-with-algorithms-and-data-structure-usingpython(使用python解决算法和数据结构) -- 基本数据结构 -- 队列
1. 什么是队列? 队列是项的有序结合,其中添加新项的一端称为队尾,移除项的一端称为队首. FIFO:先进先出 2. 队列抽象数据类型 队列操作如下: Queue() 创建一个空的新队列. 它不需要参 ...
- 【代码笔记】iOS-iphone开发之获取系统字体
代码: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. NS ...
- html基础-表格-列表(4)
今天准备为大家准备了表格和列表. 一.文章有各种数据的表格这个网页也不例外. (1).标签意思 <table>----------------------表格开始 <caption& ...
- react阻止默认事件
return false无效 必须 preventDefault
- Java线程池相关类-Executor框架
1.Executor 接口源码: public interface Executor { /** * Executes the given command at some time in the fu ...
- linux 网络命令last、lastlog、traceroute、netstat
last /usr/bin/last语法:last功能:列出目前与过去登入系统的用户信息 reboot 是重启信息 lastlog lastlog -u 502(用户ID) traceroute /b ...
- phantomjs在centos7下的安装
http://phantomjs.org/download.html 下载 Linux 64-bit 解压 tar jxvf 安装包名称.tar.bz2 pwd 查看路径 ln -sf phantom ...
- leetCode题解寻找最短字符路径
1.题目描述 2.分析 最简单的方案,对每一个字符,向两边寻找. 3.代码 vector<int> shortestToChar(string S, char C) { vector< ...
- 2017年秋季个人阅读计划 ---《掌握需求过程》第二版 pdf
这学期我们学习是软件需求分析,为了扩展视野,我们老师要求精读一本书,我根据老师推荐的书籍中找到了一本,名字叫做<掌握需求过程>,我大概浏览了一下这本书,这本书论述了软件开发中的重要课题—如 ...
- Windows Azure中WebSite 网站, Cloud Service 云服务,Virtual Machine 虚拟机的比较
在Windows Azure服务平台里,Web Site特点是: 在Windows Azure上构建高度可扩展的Web站点. 快速.轻松部署一个高度可扩展的云环境,并且可以从很小的规模开始. 使用您所 ...