/
index.js
49 lines (41 loc) · 1.25 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
let pup = require("puppeteer");
(async function() {
let puppy = await pup.launch({
headless: !false,
args: ['--no-sandbox'],
timeout: 5000
})
let bone = await puppy.newPage()
await bone.goto(
"https://global.americanexpress.com/login/en-GB?noRedirect=true&DestPage=%2Fdashboard"
)
await new Promise(y => setTimeout(y, 5000))
await bone.waitForSelector(".eliloUserId input")
await bone.type(".eliloUserId input", "snootgirl22")
await bone.waitForSelector(".eliloPassword input")
await bone.type(".eliloPassword input", "magicfriend22")
await bone.mouse.move(10, 20)
await bone.mouse.down()
await bone.mouse.up()
await bone.click("[type=submit]")
await bone.waitForNavigation()
await bone.waitForSelector(".summary-container")
await bone.waitForSelector(
"ul .undefined:nth-child(1) .value-link-inline-block"
)
let balanceElement = await bone.$(
"ul .undefined:nth-child(1) .value-link-inline-block .data-value"
)
let availableBalance = await bone.evaluate(
element => element.textContent,
balanceElement
)
let availableCredit = 3000
let currentBalance =
availableCredit - parseFloat(availableBalance.replace(/[^.0-9]/g, ""))
console.log(currentBalance)
await puppy.close()
})().catch(x => {
console.error(x)
process.exit(1)
})