-
-
Save anandsunderraman/e351485319a8a0e7df7e to your computer and use it in GitHub Desktop.
//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(); |
Addition to my comment. I've now upgraded to node 12 since it is now LTS and ran into this issue:
ERR_MODULE_NOT_FOUND selenium-webdriver/chrome
Since import of selenium-webdriver/chrome does no longer work
import chrome from "selenium-webdriver/chrome"; //broken
Here is my workaround:
import require from "requirejs";
const chrome = require("selenium-webdriver/chrome"); //works
This again took me quite a while to find out so I hope this helps!
Is it possible to disable w3c using this config?
dose anyone knows how to do the same with firefox. (open firefox with a specific profile path)
some good source: https://chromedriver.chromium.org/capabilities
and https://peter.sh/experiments/chromium-command-line-switches/
The new syntax for nodejs (NOTE: the key value)
chromeCapabilities.set("goog:chromeOptions", options);
Thank you
Thanks @qquach
thanks @EzequielCaballero
You rock!
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
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!
Thank you!!!