-
Notifications
You must be signed in to change notification settings - Fork 0
/
openTest.js
100 lines (83 loc) · 4.24 KB
/
openTest.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Playwright Documentation: https://playwright.dev/#
// XPath Cheatsheet: https://devhints.io/xpath
const playwright = require('playwright');
const fs = require('fs');
(async () => {
const browser = await playwright["chromium"].launch({ headless: false, slowMo: 50 });
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('http://linkedin.com/');
await page.click('xpath=//a[text()="Sign in"]');
await page.click('//input[@type="text"]');
await page.fill('//input[@type="text"]', 'harireddy05@gmail.com');
await page.click('//input[@type="password"]');
await page.fill('//input[@type="password"]', 'yourpasswordhere');
await page.keyboard.press('Enter');
try {
await page.click('//header[@class="msg-overlay-bubble-header"]');
} catch (e) {
console.log(e);
}
try {
// await page.click('//a[@href="/jobs/"]');
await page.click('//a[@data-test-global-nav-link="jobs"]');
} catch (e) {
await page.goto('https://www.linkedin.com/jobs/');
}
await page.click('//input[starts-with(@id, "jobs-search-box-keyword")]');
await page.fill('//input[starts-with(@id, "jobs-search-box-keyword")]', 'reactjs developer');
await page.click('//input[starts-with(@id, "jobs-search-box-location")]');
await page.fill('//input[starts-with(@id, "jobs-search-box-location")]', 'california');
await page.keyboard.press('Enter');
await page.focus('//button[starts-with(@aria-label, "LinkedIn Features filter")]');
await page.click('//button[starts-with(@aria-label, "LinkedIn Features filter")]');
await page.click('//span[text()="Easy Apply"]');
await page.keyboard.press('Enter');
const resultCountEA = await page.innerText('//small[starts-with(@class, "display-flex")]');
fs.writeFile('Report\\report.txt', `LinkedIn Job Application Report\n\nEasy Apply Search Return: ${resultCountEA} results.`, function (err) {
if (err) return console.error(err);
console.log(`Easy Apply search returned ${resultCountEA}. Added to report file.`);
});
const resultPages = await page.$$('//li[starts-with(@class, "artdeco-pagination")]');
fs.appendFile('Report\\report.txt', `\nTotal Easy Apply Result Pages: ${resultPages.length} pages.`, function (err) {
if (err) return console.error(err);
console.log(`There are ${resultPages.length} page results. Added to report file.`);
});
/* const companyList = [];
for (let i = 0; i < resultPages.length; i++) {
await page.click(`//button[starts-with(@aria-label, "Page ${i + 1}")]`);
const company = await page.$$(`//a[@data-control-name="job_card_company_link"]`);
company.forEach(async (element) => {
const text = await element.innerText();
companyList.push(text);
});
}
fs.appendFile('Report\\report.txt', `\n\nCompanies Detected: ` + `\n${companyList}`, function (err) {
if (err) return console.error(err);
// console.log(companyList);
}); */
for (let i = 0; i < resultPages.length; i++) {
// let positions = await page.$$('//a[@data-test-job-card-list__title-link="true"]');
await page.click(`//button[starts-with(@aria-label, "Page ${i + 1}")]`);
let positions = await page.$$('//div[@data-test-job-card="true"]');
console.log(positions.length);
try {
// positions.forEach(async (element) => {
// await page.click(element);
// await page.click('//button[@data-test-job-apply-button]');
// await page.click('//button[@aria-label="Submit application"]');
// await page.click('//button[@data-test-modal-close-btn]');
// });
for (let i = 0; i < positions.length; i++) {
await positions[i].click();
await page.click('//button[@data-test-job-apply-button]');
await page.click('//button[@aria-label="Submit application"]');
await page.click('//button[@data-test-modal-close-btn]');
}
} catch (e) {
console.log(e);
}
}
await page.screenshot({ path: `D:\\Projects\\test\\example.png` });
await browser.close();
})();