-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
86 lines (66 loc) · 2.4 KB
/
index.js
File metadata and controls
86 lines (66 loc) · 2.4 KB
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
const webdriver = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
const chromedriver = require('chromedriver');
const { By } = webdriver;
const fs = require('fs');
const driver = new webdriver.Builder().forBrowser('chrome').build();
driver.get('https://www.inquirer.com');
let fonts = {};
let classNames = {};
let output = {
classNames,
fonts
};
const scDir = './screenshots';
if (!fs.existsSync(scDir)){
fs.mkdirSync(scDir);
}
const expandElems = async () => {
// retrieve all elements that are buttons that expand/collapse content
const expandableElems = await driver.findElements(By.xpath('//button[@aria-expanded="false"]'));
const n = expandableElems.length;
for (let i = 0; i < n; i++) {
try {
// click to reveal hidden elements making them accesible from DOM
await expandableElems[i].click();
// search through nodes that have been revealed from expanded content
await findTextNodes();
} catch (e) {
}
}
const data = JSON.stringify(output);
fs.writeFileSync('output.json', data);
}
const findTextNodes = async () => {
try {
// retrieve all elements accesible from DOM
const elements = await driver.findElements(By.xpath('//*'));
const n = elements.length;
for (let i = 0; i < n; i++) {
let fontFamily = await elements[i].getCssValue('font-family');
if (fontFamily === '"Ringside Regular SSm", Verdana, sans-serif') {
let elem = elements[i];
try {
// take screenshot of element that matches above font family
let sc = await elem.takeScreenshot(true);
fs.writeFileSync(`${scDir}/found_${i}`, sc, 'base64');
// retrieve classes from element that has above font family
let className = await elem.getAttribute('class');
if (classNames[className] >= 0) {
classNames[className]++;
} else {
classNames[className] = 1;
}
} catch (e) {
}
}
if (fonts[fontFamily] >= 0) {
fonts[fontFamily]++;
} else {
fonts[fontFamily] = 1;
}
}
} catch (e) {
}
}
expandElems();