Skip to content
This repository was archived by the owner on Jan 19, 2021. It is now read-only.

Commit 6f39287

Browse files
authored
Merge pull request #22 from supernova13892/master
Added Instagram login example in the list.
2 parents 169852b + 2f50975 commit 6f39287

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

3. login/instagram.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* @name Instagram
3+
*
4+
* @desc Logs into Instagram with credentials. Provide your username and password as environment variables when running the script, i.e:
5+
* `INSTAGRAM_USER=myuser INSTAGRAM_PWD=mypassword node instagram.js`
6+
*
7+
*/
8+
const puppeteer = require('puppeteer')
9+
const screenshot = 'instagram.png';
10+
(async () => {
11+
const browser = await puppeteer.launch({
12+
headless: false
13+
})
14+
const page = await browser.newPage()
15+
await page.goto("https://www.instagram.com/accounts/login/?source=auth_switcher", {
16+
waitUntil: 'networkidle2'
17+
});
18+
19+
//email
20+
await page.waitForSelector("[name='username']");
21+
// await page.click("[name='username']");
22+
await page.type("[name='username']", process.env.INSTAGRAM_USER);
23+
24+
//password
25+
await page.keyboard.down("Tab");
26+
//uncomment the following if you want the passwor dto be visible
27+
// page.$eval("._2hvTZ.pexuQ.zyHYP[type='password']", (el) => el.setAttribute("type", "text"));
28+
await page.keyboard.type(process.env.INSTAGRAM_PWD);
29+
30+
//the selector of the "Login" button
31+
// await page.click("._0mzm-.sqdOP.L3NKy>.Igw0E.IwRSH.eGOV_._4EzTm");
32+
33+
//we find the Login btn using the innerText comparison because the selector used for the btn might be unstable
34+
await page.evaluate(() => {
35+
let btns = [...document.querySelector(".HmktE").querySelectorAll("button")];
36+
btns.forEach(function (btn) {
37+
if (btn.innerText == "Log In")
38+
btn.click();
39+
});
40+
});
41+
42+
//Optional
43+
//check if the element asking to download the app arises
44+
// try {
45+
// await loginPage.waitForSelector("._3m3RQ._7XMpj",{
46+
// timeout:3000
47+
// });
48+
// await loginPage.click("._3m3RQ._7XMpj");
49+
// } catch (err) {
50+
51+
// }
52+
53+
//Optional
54+
//check if the app asks for notifications
55+
// try {
56+
// await loginPage.waitForSelector(".aOOlW.HoLwm",{
57+
// timeout:5000
58+
// });
59+
// await loginPage.click(".aOOlW.HoLwm");
60+
// } catch (err) {
61+
62+
// }
63+
64+
await page.waitForSelector(".glyphsSpriteMobile_nav_type_logo");
65+
66+
await page.screenshot({ path: screenshot });
67+
68+
browser.close()
69+
console.log('See screenshot: ' + screenshot)
70+
})()

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ You can run these scripts in the [https://puppeteersandbox.com](https://puppetee
3333
* [Github](#github)
3434
* [Google Social Login](#google-social-login)
3535
* [Twitter](#twitter)
36+
* [Instagram](#instagram)
3637
- [4. shopping-carts](#4-shopping-carts)
3738
* [Staples shopping cart](#staples-shopping-cart)
3839
* [Walmart shopping cart](#walmart-shopping-cart)
@@ -159,6 +160,11 @@ Logs into Twitter. Provide your username and password as environment variables w
159160

160161

161162
[3. login/twitter.js](https://github.com/checkly/puppeteer-examples/blob/master/3.%20login/twitter.js)
163+
### Instagram
164+
Logs into Instagram. Provide your username and password as environment variables when running the script, i.e: `INSTAGRAM_USER=myuser INSTAGRAM_PWD=mypassword node instagram.js`
165+
166+
167+
[3. login/instagram.js](https://github.com/checkly/puppeteer-examples/blob/master/3.%20login/instagram.js)
162168
## 4. shopping-carts
163169
How to handle shopping cart functions like adding and removing items.
164170
### Staples shopping cart

0 commit comments

Comments
 (0)