Skip to content

Instantly share code, notes, and snippets.

@anandsunderraman
Last active July 19, 2024 12:13
Show Gist options
  • Save anandsunderraman/e351485319a8a0e7df7e to your computer and use it in GitHub Desktop.
Save anandsunderraman/e351485319a8a0e7df7e to your computer and use it in GitHub Desktop.
Selenium Web Driver Set Chrome Options
//import the selenium web driver
var webdriver = require('selenium-webdriver');
var chromeCapabilities = webdriver.Capabilities.chrome();
//setting chrome options to start the browser fully maximized
var chromeOptions = {
'args': ['--test-type', '--start-maximized']
};
chromeCapabilities.set('chromeOptions', chromeOptions);
var driver = new webdriver.Builder().withCapabilities(chromeCapabilities).build();
@ramrami
Copy link

ramrami commented Oct 17, 2020

Thank you

@gulraiz-malhi
Copy link

Thanks @qquach

@jcharnley
Copy link

@purejgleason
Copy link

You rock!

@novwhisky
Copy link

For newer versions of Node with ES modules enabled (14+)

import chrome from 'selenium-webdriver/chrome.js';

let opts = new chrome.Options();
opts.excludeSwitches('enable-automation'); // disable 'Chrome is being controlled by automation' banner

@blablabla1234678
Copy link

Sample code for 2024

import {Builder, Capabilities} from 'selenium-webdriver';

const caps = Capabilities.chrome();
caps.set('goog:chromeOptions', {
    'args': ['--headless']
});

const driver =  new Builder()
    .forBrowser('chrome')
    .withCapabilities(caps)
    .build();

(async () => {
    await driver.get('https://www.geeksforgeeks.org/');
    // ...
    await driver.quit();
})();

It was hard to find this gist, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment