Created
May 25, 2018 14:50
-
-
Save nkgrnkgr/a70a7195a13e089803d011abbb30e7e6 to your computer and use it in GitHub Desktop.
selenium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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