forked from hkirat/linkedin-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebPage.js
77 lines (66 loc) · 2.17 KB
/
WebPage.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
require("dotenv").config();
const { Builder, By, until } = require("selenium-webdriver");
const chrome = require("selenium-webdriver/chrome");
function initOptions(o) {
// o.addArguments("headless");
o.addArguments("disable-infobars");
o.addArguments("no-sandbox");
o.addArguments(
"user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36 RuxitSynthetic/1.0 v6419931773 t38550 ath9b965f92 altpub"
);
o.setUserPreferences({
credential_enable_service: false,
});
}
const BasePage = function (customAudio = null) {
let o = new chrome.Options();
initOptions(o);
this.driver = new Builder()
.withCapabilities({ acceptSslCerts: true, acceptInsecureCerts: true })
.setChromeOptions(o)
.forBrowser("chrome")
.build();
this.visit = async function (theUrl) {
return await this.driver.get(theUrl);
};
this.findById = async function (id) {
await this.driver.wait(
until.elementLocated(By.id(id)),
15000,
"Looking for element"
);
return await this.driver.findElement(By.id(id));
};
this.findByClassName = async function (name) {
const els = await this.driver.wait(
until.elementsLocated(By.className(name)),
15000,
"Looking for element"
);
return els[els.length - 1];
return await this.driver.findElement(By.className(name));
};
this.signin = async function () {
let name = process.env.USERNAME || "";
let password = process.env.PASSWORD || "";
let input = await this.findById("session_key");
await input.sendKeys(name);
let input2 = await this.findById("session_password");
await input2.sendKeys(password);
let button = await this.findByClassName(
"sign-in-form__submit-btn--full-width"
);
console.log(button);
await button.click();
};
this.pressAcceptButton = async function () {
let buttons = await this.findByClassName(
"artdeco-button--secondary invitation-card__action-btn"
);
await buttons.click();
};
this.scrollToBottom = async function () {
this.driver.executeScript("window.scrollTo(0, document.body.scrollHeight)");
};
};
module.exports = BasePage;