-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathevaluation_roaster.js
57 lines (44 loc) · 1.94 KB
/
evaluation_roaster.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
'use strict'
const puppeteer = require('puppeteer')
const timeout = { timeout:500000 }
;(async () => {
const browser = await puppeteer.launch({headless: false}); // default is true
const page = await browser.newPage();
await navigate_entity(page,'https://student.guc.edu.eg/External/Student/Staff/EvaluateStaff.aspx');
await evaluate_entity(page, '#stfIdLst', 'https://student.guc.edu.eg/External/Student/Staff/EvaluateStaff.aspx');
await navigate_entity(page, 'https://student.guc.edu.eg/External/Student/Course/EvaluateCourse.aspx');
await evaluate_entity(page, '#crsIdLst', 'https://student.guc.edu.eg/External/Student/Course/EvaluateCourse.aspx');
await browser.close();
})();
async function navigate_entity(page, url) {
await page.goto(url, timeout);
}
async function evaluate_entity(page, selector_name, url) {
const option_values = await page.evaluate((selector_name) => {
let values = [];
document.querySelectorAll(`${selector_name} option`).forEach(node => {
if (node.value) values.push(node.value);
})
return values;
}, selector_name)
for (let i = 0; i < option_values.length; i++) {
await navigate_entity(page, url);
await page.select(selector_name, option_values[i]);
await fill_entity_form(page);
}
}
async function fill_entity_form(page) {
await page.waitForSelector('#msgLbl');
let evaluated = await page.evaluate(() => document.querySelector('#msgLbl').innerText);
if (evaluated.length > 0 ) return
await page.evaluate(() => {
document.querySelectorAll("input[value='1']").forEach(input => {
input.click();
});
});
await Promise.all([
page.evaluate(() => { document.querySelector("input[name='pstEvalBtn']").click();}),
page.waitForNavigation({waitUntil: 'networkidle0'}),
]);
await page.screenshot({path: `proof_${Math.random()}.png`});
}