Skip to main content

Selenium

Web-driver protocol used by Selenium is supported. As there are many ways to carry out a remote connection, refer to the appropriate libraries’ documentation. Here is an example of the joint chrome-webdriver library and BrowserCloud usage.

Before

const webdriver = require('selenium-webdriver');
const fs = require('fs');

const chromeCapabilities = webdriver.Capabilities.chrome();
chromeCapabilities.set('goog:chromeOptions', {
// Set args similar to puppeteer's for best performance
args: [
"--disable-background-timer-throttling",
"--disable-backgrounding-occluded-windows",
"--disable-breakpad",
"--disable-component-extensions-with-background-pages",
"--disable-dev-shm-usage",
"--disable-extensions",
"--disable-features=TranslateUI,BlinkGenPropertyTrees",
"--disable-ipc-flooding-protection",
"--disable-renderer-backgrounding",
"--enable-features=NetworkService,NetworkServiceInProcess",
"--force-color-profile=srgb",
"--hide-scrollbars",
"--metrics-recording-only",
"--mute-audio",
"--headless",
"--no-sandbox"
]
});

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

(async () => {
try {
await driver.get('https://www.example.com/');

// Take screenshot of results page. Save to disk.
const base64png = await driver.takeScreenshot();
fs.writeFileSync('.no-git/screenshot.png', new Buffer(base64png, 'base64'));
} finally {
driver.quit();
}
})();

Remote connect to cloud

const webdriver = require('selenium-webdriver');
const fs = require('fs');

const chromeCapabilities = webdriver.Capabilities.chrome();
chromeCapabilities.set('browsercloud.token', 'MY-TOKEN');
chromeCapabilities.set('goog:chromeOptions', {
args: [
"--disable-background-timer-throttling",
"--disable-backgrounding-occluded-windows",
"--disable-breakpad",
"--disable-component-extensions-with-background-pages",
"--disable-dev-shm-usage",
"--disable-extensions",
"--disable-features=TranslateUI,BlinkGenPropertyTrees",
"--disable-ipc-flooding-protection",
"--disable-renderer-backgrounding",
"--enable-features=NetworkService,NetworkServiceInProcess",
"--force-color-profile=srgb",
"--hide-scrollbars",
"--metrics-recording-only",
"--mute-audio",
"--headless",
"--no-sandbox"
]
});

const driver = new webdriver.Builder()
.forBrowser('chrome')
.withCapabilities(chromeCapabilities)
// Specify browsercloud for the server
.usingServer('https://chrome-us.browsercloud.io/webdriver')
.build();

(async () => {
try {
await driver.get('https://www.example.com/');

// Take screenshot of results page. Save to disk.
const base64png = await driver.takeScreenshot();
fs.writeFileSync('.no-git/screenshot.png', new Buffer(base64png, 'base64'));
} finally {
driver.quit();
}
})();

The ?token=MY-TOKEN fails to be added as there are the Selenium libraries' limits such as query-string parameters dropped from the URL server.