-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
84 lines (59 loc) · 2.34 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
require('dotenv').config()
const puppeteer = require('puppeteer');
const login = require('./pages/login')
const shopping_cart = require('./pages/shopping_cart.js')
async function runLoop(browser, page) {
const newPage = await browser.newPage()
console.log("Navigating to new page")
await newPage.goto(page.url())
await newPage.waitFor(2500)
console.log("Checking shopping cart")
const classes = await shopping_cart(newPage)
// console.log(newClasses)
console.log("Checking to see if a class is open")
var classOpen = false
const selectionResults = await classes.map(async (classInfo) => {
classInfo = await classInfo
if (classInfo.classAvailable) {
// await obj.rowElement.click(`input[name="P_SELECT$${obj.rowIndex}"]`)
const checkbox = await classInfo.rowElement.$(`input[name="P_SELECT$${classInfo.rowIndex}"]`)
await checkbox.click()
return true
}
return false
})
await Promise.all(selectionResults).then(async (results) => {
const frame = await newPage.$('iframe[name="TargetContent"]')
const contentFrame = await frame.contentFrame()
await contentFrame.waitFor(5000)
if (results.includes(true)) {
console.log("Attempting to register for classes")
await Promise.all([
contentFrame.waitForNavigation({ waitUntil: 'networkidle2' }),
contentFrame.click('a[name="DERIVED_REGFRM1_LINK_ADD_ENRL"]'),
])
console.log("Registering for classes")
await contentFrame.click('a[name="DERIVED_REGFRM1_SSR_PB_SUBMIT"]')
await contentFrame.waitFor(2500)
}
})
console.log("Closing original page")
await page.close()
console.log("Rerunning class check loop...")
runLoop(browser, newPage)
}
async function run() {
try {
const browser = await puppeteer.launch()
const page = await browser.newPage()
// await page.goto('https://www.google.com', { waitUntil: 'networkidle2' })
await page.setViewport({ width: 1366, height: 768 })
await login(page)
const classes = await shopping_cart(page)
await runLoop(browser, page, classes)
// await browser.close()
} catch(e) {
console.log("Error: ", e)
}
}
run()