Skip to content

Instantly share code, notes, and snippets.

@nkgrnkgr
Created May 25, 2018 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkgrnkgr/a70a7195a13e089803d011abbb30e7e6 to your computer and use it in GitHub Desktop.
Save nkgrnkgr/a70a7195a13e089803d011abbb30e7e6 to your computer and use it in GitHub Desktop.
selenium
const webdriver = require('selenium-webdriver');
const {
Builder,
By,
Key,
until
} = require('selenium-webdriver');
let driver;
let expiry = new Date(Date.now() + (10 * 60 * 1000));
const cookie = {
name: "hoge",
value: "fuga",
path: "/",
domain: "www.google.co.jp",
expiry: expiry
}
async function accessGoogle() {
driver = new webdriver.Builder()
.withCapabilities(webdriver.Capabilities.chrome())
.build();
try {
await driver.get('https://www.google.co.jp');
await driver.wait(until.elementLocated(By.id('gsr')), 2000);
} catch (e) {
console.error(e);
} finally {
await driver.quit();
console.log("finished");
}
};
const count = 3;
// 非同期
for (let i = 0; i < count; i++) {
accessGoogle();
}
// 同期
(async () => {
for (let i = 0; i < count; i++) {
await accessGoogle();
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment