Chrome Capabilities & ChromeOptions
Capabilities & ChromeOptions
Capabilities & ChromeOptions
Capabilities are options that you can use to customize and configure a ChromeDriver session. This page documents all ChromeDriver supported capabilities and how to use them.
There are two ways to specify capabilities.
- The first is to use the
ChromeOptionsclass. - If your client library does not have a
ChromeOptionsclass (like the selenium ruby client), you can specify the capabilities directly as part of theDesiredCapabilities.
Using the ChromeOptions class
You can create an instance of ChromeOptions, which has convenient methods for setting ChromeDriver-specific capabilities. You can pass the ChromeOptions object directly into the ChromeDriver constructor:
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("/path/to/extension.crx"));
ChromeDriver driver = new ChromeDriver(options);
Alternatively, you can add the options to an already existing DesiredCapabilities object, which is useful when need to specify other WebDriver capabilities not specific to ChromeDriver.
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
// Add the WebDriver proxy capability.
Proxy proxy = new Proxy();
proxy.setHttpProxy("myhttpproxy:3337");
capabilities.setCapability("proxy", proxy); // Add ChromeDriver-specific capabilities through ChromeOptions.
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("/path/to/extension.crx"));
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);
Using DesiredCapabilities directly
The ChromeOptions class uses DesiredCapabilities underneath. To use DesiredCapabilities directly, you need to know the name of the capability and the type of value it takes. See the full list further below.
Java
Map<String, Object> chromeOptions = new Map<String, Object>();
chromeOptions.put("binary", "/usr/lib/chromium-browser/chromium-browser");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
WebDriver driver = new ChromeDriver(capabilities);
Ruby
caps = Selenium::WebDriver::Remote::Capabilities.chrome("chromeOptions" => {"args" => [ "--disable-web-security" ]})
driver = Selenium::WebDriver.for :remote, url: 'http://localhost:4444/wd/hub' desired_capabilities: caps
Common use cases
Use custom profile (also called user data directory)
By default, ChromeDriver will create a new temporary profile for each session. At times you may want to set special preferences or just use a custom profile altogether. If the former, you can use the 'chrome.prefs' capability (described later below) to specify preferences that will be applied after Chrome starts. If the latter, you can use the user-data-dir Chrome command-line switch to tell Chrome which profile to use:
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=/path/to/your/custom/profile");
You can create your own custom profile by just running Chrome (on the command-line or through ChromeDriver) with the user-data-dir switch set to some new directory. If the path doesn't exist, Chrome will create a new profile in the specified location. You can then modify the profile settings as desired, and ChromeDriver can use the profile in the future. Open chrome://version in the browser to see what profile Chrome is using.
Start Chrome maximized
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
Using a Chrome executable in a non-standard location
ChromeOptions options = new ChromeOptions();
options.setBinary("/path/to/other/chrome/binary");
Set a Chrome preference
ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_settings.popups", 0);
options.setExperimentalOption("prefs", prefs);
List of recognized capabilities
This is a list of all the WebDriver-standard capabilities that ChromeDriver supports:
Proxy object
See http://code.google.com/p/selenium/wiki/DesiredCapabilities#Proxy_JSON_Object
loggingPrefs object
See https://code.google.com/p/selenium/wiki/DesiredCapabilities#JSON_object
chromeOptions object
This is a list of all the Chrome-specific desired capabilities, which all are under the chromeOptions dictionary.
If possible, use the ChromeOptions class instead of specifying these directly.
Name
Type
Default
Description
args
list of strings
List of command-line arguments to use when starting Chrome. Arguments with an associated value should be separated by a '=' sign (e.g., ['start-maximized', 'user-data-dir=/tmp/temp_profile']). See here for a list of Chrome arguments.
binary
string
Path to the Chrome executable to use (on Mac OS X, this should be the actual binary, not just the app. e.g., '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome')
extensions
list of strings
A list of Chrome extensions to install on startup. Each item in the list should be a base-64 encoded packed Chrome extension (.crx)
localState
dictionary
A dictionary with each entry consisting of the name of the preference and its value. These preferences are applied to the Local State file in the user data folder.
prefs
dictionary
A dictionary with each entry consisting of the name of the preference and its value. These preferences are only applied to the user profile in use. See the 'Preferences' file in Chrome's user data directory for examples.
detach
boolean
false
If false, Chrome will be quit when ChromeDriver is killed, regardless of whether the session is quit. If true, Chrome will only be quit if the session is quit (or closed). Note, if true, and the session is not quit, ChromeDriver cannot clean up the temporary user data directory that the running Chrome instance is using.
debuggerAddress
string
An address of a Chrome debugger server to connect to, in the form of <hostname/ip:port>, e.g. '127.0.0.1:38947'
excludeSwitches
list of strings
List of Chrome command line switches to exclude that ChromeDriver by default passes when starting Chrome. Do not prefix switches with --.
minidumpPath
string
Directory to store Chrome minidumps . (Supported only on Linux.)
mobileEmulation
dictionary
A dictionary with either a value for “deviceName,” or values for “deviceMetrics” and “userAgent.” Refer to Mobile Emulation for more information.
perfLoggingPrefs
dictionary
An optional dictionary that specifies performance logging preferences. See below for more information.
windowTypes
list of strings
A list of window types that will appear in the list of window handles. For access to <webview> elements, include "webview" in this list.
perfLoggingPrefs object
The perfLoggingPrefs dictionary has the following format (all keys are optional):
Name
Type
Default
Description
enableNetwork
boolean
true
Whether or not to collect events from Network domain.
enablePage
boolean
true
Whether or not to collect events from Page domain.
enableTimeline
boolean
true (false if tracing is enabled)
Whether or not to collect events from Timeline domain. Note: when tracing is enabled, Timeline domain is implicitly disabled, unless enableTimeline is explicitly set to true.
tracingCategories
string
(empty)
A comma-separated string of Chrome tracing categories for which trace events should be collected. An unspecified or empty string disables tracing.
bufferUsageReportingInterval
positive integer
1000
The requested number of milliseconds between DevTools trace buffer usage events. For example, if 1000, then once per second, DevTools will report how full the trace buffer is. If a report indicates the buffer usage is 100%, a warning will be issued.
Returned Capabilities
This is a list of all the Chrome-specific returned capabilities. (i.e., what ChromeDriver returns when you create a new session)
Name
Type
Description
chrome.chromedriverVersion
string
version of ChromeDriver
userDataDir
string
path to user data directory that Chrome is using; note, this is inside a 'chrome' dictionary
ChromeDriver server command line arguments
Run chromedriver --help to see command line arguments for your version.
Chrome Capabilities & ChromeOptions的更多相关文章
- Capabilities & ChromeOptions
https://sites.google.com/a/chromium.org/chromedriver/capabilities http://stackoverflow.com/questions ...
- chromedriver Capabilities & ChromeOptions
Capabilities are options that you can use to customize and configure a ChromeDriver session. This pa ...
- selenium启动Chrome浏览器和禁止证书错误提示弹出
要把ChromeDriver放到代码中的文件夹中c://*******Application public static WebDriver WebDriverRun(WebDriver driver ...
- (原创)如何使用selenium 驱动chrome浏览器并且打开方式为手机模式-转载请注明出处
随着移动设备使用率的不断增加,移动页面的测试也变得越来越重要. 对于互联网公司M站的测试,如果不通过专用的appium等移动端测试工具是否还有方便快捷的办法呢?答案当然是有啊. 使用chrome dr ...
- Webdriver设置Chrome属性
1. ChromeDriver加载插件 File file = new File ("files\\youtube.crx"); ChromeOptions options = n ...
- Selenium2学习-006-WebUI自动化实战实例-004-解决 Chrome 浏览器证书提示:--ignore-certificate-errors
此文主要讲述 Java 运行 Selenium 脚本时,如何消除 Chrome 浏览器启动后显示的证书错误报警提示,附带 Chrome 参数使浏览器最大化的参数. 希望能对初学 Selenium2 W ...
- 【转】利用 selenium 的 webdrive 驱动 headless chrome
1.参考 使用 headless chrome进行测试 2.概念 Headless模式解决了什么问题: 自动化工具例如 selenium 利用有头浏览器进行测试,面临效率和稳定性的影响,所以出现了 H ...
- Selenium chrome配置代理Python版
环境: windows 7 + Python 3.5.2 + Selenium 3.4.2 + Chrome Driver 2.29 + Chrome 58.0.3029.110 (64-bit) S ...
- Selenium Chrome
Chrome版本不变 发现在 Selenium-server-standalone-2.39.0.jar 中可全屏 Selenium-server-standalone-3.8.1.jar 中不可全屏 ...
随机推荐
- Ngix配置,让所有请求指向同一个文件
统一入口使所有请求在同一个文件先验证处理,Ngix添加如下代码: location / { try_files '' /index.php; }
- App测试基本流程详解
1 APP测试基本流程 1.1流程图 1.2测试周期 测试周期可按项目的开发周期来确定测试时间,一般测试时间为两三周(即15个工作日),根据项目情况以及版本质量可适当缩短或延长测试时间. 1.3测试资 ...
- python3.x 编码问题
- HDU 4431 Mahjong(枚举+模拟)(2012 Asia Tianjin Regional Contest)
Problem Description Japanese Mahjong is a four-player game. The game needs four people to sit around ...
- JAVA课程设计——植物大战僵尸(团队)
1.团队名称.团队成员介绍 团名:嗷嗷嗷嗷嗷 吴军霖(组长) 写得一手好代码也改得一手好bug 代码整洁好看源于强迫症 大概没有什么不会的东西叭 真正的王者段位 欧阳震霆(组员) 同样擅长写代码 在青 ...
- lintcode-109-数字三角形
109-数字三角形 给定一个数字三角形,找到从顶部到底部的最小路径和.每一步可以移动到下面一行的相邻数字上. 注意事项 如果你只用额外空间复杂度O(n)的条件下完成可以获得加分,其中n是数字三角形的总 ...
- 基于bootstrap动态分页
bootstrap本身的分页有分页组件 但是却是静态的,无法满足要求,分页必须根据当前的总页数来展示 使用插件bootstrap-paginator github下载地址 https://github ...
- 微信小程序小程序使用scroll-view不能使用下拉刷新的解决办法
<scroll-view class="movie-grid-container" scroll-y="true" scroll-x="fals ...
- Java 利用枚举实现单例模式
引言 单例模式比较常见的实现方法有懒汉模式,DCL模式公有静态成员等,从Java 1.5版本起,单元素枚举实现单例模式成为最佳的方法. Java枚举 基本用法 枚举的用法比较多,本文主要旨在介绍利用枚 ...
- hibernate对单表的增删改查
ORM: 对象关系映射(英语:Object Relational Mapping,简称ORM,或O/RM,或O/R mapping) 实现对单表的增删改查 向区域表中增加数据: 第一步: 新建一个Da ...