Chrome specific functionality
By default, Selenium 4 is compatible with Chrome v75 and greater. Note that the version of the Chrome browser and the version of chromedriver must match the major version.
Options
Capabilities common to all browsers are described on the Options page.
Capabilities unique to Chrome can be found at Google’s page for Capabilities & ChromeOptions
Starting a Chrome session with basic defined options looks like this:
ChromeOptions options = new ChromeOptions();
driver = new ChromeDriver(options);
options = ChromeOptions()
driver = webdriver.Chrome(options=options)
var options = new ChromeOptions();
var driver = new ChromeDriver(options);
options = Selenium::WebDriver::Options.chrome
@driver = Selenium::WebDriver.for :chrome, options: options
const Options = new Chrome.Options();
let driver = await env
.builder()
.setChromeOptions(Options)
.build();
Here are a few common use cases with different capabilities:
Arguments
The args
parameter is for a list of Command Line Switches
used when starting the browser.
Commonly used args include --start-maximized
and --headless=new
Add an argument to options:
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless=new");
driver = new ChromeDriver(options);
chrome_options = ChromeOptions()
chrome_options.add_argument("--headless=new")
var options = new ChromeOptions();
options.AddArgument("--headless=new");
var driver = new ChromeDriver(options);
options = Selenium::WebDriver::Options.chrome(args: ['--headless=new'])
let driver = await env
.builder()
.setChromeOptions(options.addArguments('--headless=new'))
.build();
Start browser in a specified location
The binary
parameter takes the path of an alternate location of browser to use. With this parameter you can
use chromedriver to drive various Chromium based browsers.
Add a browser location to options:
let driver = await env
.builder()
.setChromeOptions(options.setChromeBinaryPath(`Path to chrome binary`))
.build();
Add extensions
The extensions
parameter accepts crx files. As for unpacked directories,
please use the load-extension
argument instead, as mentioned in
this post.
Add an extension to options:
Coding Help
Check our contribution guidelines and code example formats if you’d like to help.
Keeping browser open
Setting the detach
parameter to true will keep the browser open after the driver process has been quit.
Add a binary to options:
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("detach", true);
driver = new ChromeDriver(options);
chrome_options = ChromeOptions()
chrome_options.add_experimental_option("detach", True)
options = Selenium::WebDriver::Options.chrome(detach: true)
let driver = await env
.builder()
.setChromeOptions(options.detachDriver(true))
.build();
Excluding arguments
Chrome adds various arguments, if you do not want those arguments added, pass them into excludeSwitches
.
A common example is to turn the popup blocker back on.
Set excluded arguments on options:
chrome_options = ChromeOptions()
chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])
options = Selenium::WebDriver::Options.chrome(exclude_switches: ['enable-automation'])
let driver = await env
.builder()
.setChromeOptions(options.excludeSwitches('enable-automation'))
.build();
Casting
You can drive Chrome Cast devices, including sharing tabs
Coding Help
Check our contribution guidelines and code example formats if you’d like to help.
Network conditions
You can simulate various network conditions.
The following examples are for local webdrivers. For remote webdrivers, please refer to the Remote WebDriver page.
Coding Help
Check our contribution guidelines and code example formats if you’d like to help.
Logs
Coding Help
Check our contribution guidelines and code example formats if you’d like to help.
Permissions
Coding Help
Check our contribution guidelines and code example formats if you’d like to help.
DevTools
See the Chrome DevTools section for more information about using Chrome DevTools