Skip to content

Instantly share code, notes, and snippets.

@BooookStore
Created October 27, 2019 03:05
Show Gist options
  • Save BooookStore/67b26734c95759572cdaf11edb801ccf to your computer and use it in GitHub Desktop.
Save BooookStore/67b26734c95759572cdaf11edb801ccf to your computer and use it in GitHub Desktop.
headless chrome + selenium + webdriverio
const selenium = require('selenium-standalone');
const {remote} = require('webdriverio');
selenium.install((result) => console.log({result}));
selenium.start((err, child) => {
(async () => {
const browser = await remote({
logLevel: 'trace',
capabilities: {
browserName: 'chrome',
'goog:chromeOptions': {
args: ['--headless']
}
}
})
await browser.url('https://duckduckgo.com')
const inputElem = await browser.$('#search_form_input_homepage')
await inputElem.setValue('WebdriverIO')
const submitBtn = await browser.$('#search_button_homepage')
await submitBtn.click()
console.log(await browser.getTitle()) // outputs: "Title is: WebdriverIO (Software) at DuckDuckGo"
await browser.deleteSession()
child.kill();
})().catch((e) => console.error(e));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment