Last active
September 13, 2019 23:26
-
-
Save hatmer/db22fa475d32d7adc52af44994a6901c to your computer and use it in GitHub Desktop.
Automatic Website Login with Puppeteer
This file contains hidden or 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 puppeteer = require('puppeteer'); | |
| var url = "https://example.com"; | |
| var username = "test"; | |
| var password = "password"; | |
| (async () => { | |
| const browser = await puppeteer.launch({ignoreHTTPSErrors: false, headless: false}); | |
| const page = await browser.newPage(); | |
| page.on('dialog', async dialog => { | |
| console.log("found dialog") | |
| await dialog.accept();}); | |
| await page.goto(url); | |
| await page.waitForSelector('input[name="username"]'); | |
| console.log("logging in..."); | |
| await page.type('input[name="username"]', username); | |
| await page.type('input[name="password"]', password); | |
| await page.click('button[type="submit"]'); | |
| console.log("done") | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment