chromedriver 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.
- The first is to use the
ChromeOptions
class. - If your client library does not have a
ChromeOptions
class (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
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 theuser-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
Proxy
object
See http://code.google.com/p/selenium/wiki/DesiredCapabilities#Proxy_JSON_Object
loggingPrefs
object
chromeOptions
object
This is a list of all the Chrome-specific desired capabilities, which all are under the chromeOptions
dictionary.
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
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 Capabilities & ChromeOptions的更多相关文章
- Capabilities & ChromeOptions
https://sites.google.com/a/chromium.org/chromedriver/capabilities http://stackoverflow.com/questions ...
- Chrome Capabilities & ChromeOptions
Capabilities & ChromeOptions Chrome Extensions Contributing Downloads Getting started Android Ch ...
- chromedriver release note
----------ChromeDriver v2.25 (2016-10-25)---------- Supports Chrome v53-55 Resolved issue 1547: Chro ...
- 【转】传递给Appium服务器以开启相应安卓Automation会话的Capabilities的几点说明
原文地址:http://blog.csdn.net/zhubaitian/article/details/39431307 Desired Capabilities是由客户端发送给Appium服务器端 ...
- Appium webdriver的capabilities配置
Capabilities是由客户端发送给Appium服务器端的用来告诉服务器去启动哪种我们想要的会话的一套键值对集合.当中也有一些键值对是用来在自动化的过程中修改服务器端的行为方式. 必填的项目: d ...
- chromedriver与chrome最新版本对应表
如果需要看到最新版的chromedriver和chrome版本对应问题,点击http://npm.taobao.org/mirrors/chromedriver/,点击最新版本的chromedrive ...
- ChromeDriver与Chrome版本对应关系
备注: 下载ChromeDriver的时候,可以在notes.txt文件中查看版本对应关系. ----------ChromeDriver v2.29 (2017-04-04)---------- S ...
- 【自动化测试】selenium之 chromedriver与chrome版本映射表
chromedriver版本 支持的Chrome版本 v2.30 v58-60 v2.29 v56-58 v2.28 v55-57 v2.27 v54-56 v2.26 v53-55 v2.25 v5 ...
- 使用selenium的WebDriver和ChromeDriver实现UI自动化
下载chromedriver chromedriver与chrome的对应关系表:http://blog.csdn.net/huilan_same/article/details/51896672 下 ...
随机推荐
- Unity游戏开发之C#快速入门
C#是微软团队在开发.NET框架时开发的,它的构想接近于C.C++,也和JAVA十分相似,有许多强大的编程功能. 个人感受是C#吸收了众多编程语言的优点,从中可以看到C.C++.Java.Javasc ...
- oracle中 char,varchar,varchar2的区别
区别: 1. CHAR的长度是固定的,而VARCHAR2的长度是可以变化的, 比如,存储字符串“abc",对于CHAR (20),表示你存储的字符将占20个字节(包括17个空字符) ...
- linux——(2)文件权限与目录配置
概念一:用户与用户组 对linux下的每一个文件或者目录来说,访问者都有三种身份:所有者,用户组,其他人.这三种人对于同一个文件的权限是可以分开设定的. 概念二:linux文件权限 文件和目录都有3种 ...
- Abp数据库迁移注意事项
前记:昨天下载了一个Abp模板,然后尝试利用EF CodeFirst进行数据库生成操作,然后就是一直报错 在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误.未找到或无法访问服务 ...
- Python开发基础-Day16import模块导入和包的调用
模块概念 在Python中,一个.py文件就称之为一个模块(Module).使用模块组织代码,最大的好处是大大提高了代码的可维护性 模块一共三种:python标准库.第三方模块.应用程序自定义模块. ...
- js中ajax的异步性
最近项目里遇到ajax异步性的问题,简化后的代码如下: function ajaxGetEvents(calendarView, time) { var year = time.getFullYear ...
- JAVA EE 项目常用知识 之AJAX技术实现select下拉列表联动的两种用法(让你真正理解ajax)
ajax 下拉列表联动的用法. ajax的定义: AJAX 是一种用于创建快速动态网页的技术. 通过在后台与服务器进行少量数据交换,AJAX 可以使网页实现异步更新.这意味着可以在不重新加载整个网页的 ...
- 洛谷 [AHOI2001]质数和分解
题目描述 Description 任何大于 1 的自然数 n 都可以写成若干个大于等于 2 且小于等于 n 的质数之和表达式(包括只有一个数构成的和表达式的情况),并且可能有不止一种质数和的形式.例 ...
- JS/JQuery判断是否移动设备+JS/JQuery判断浏览器类型
原文:https://blog.csdn.net/Little_Stars/article/details/48624669 JS代码如下(点击事件依赖JQuery): //判断设备类型 $(&quo ...
- 2014 linux
[51CTO精选译文]每年大概12月前后,人们喜欢给出种种预测,预言他们认为未来一年技术界会出现什么样的变化.本文也不例外,只不过侧重介绍2014年值得关注的十大最受关注的Linux发行版(桌面版或移 ...