-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (32 loc) · 1.63 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
50
const playwright = require('playwright');
const chalk = require('chalk');
const log = console.log;
async function main(headless = true) {
const browser = await playwright.chromium.launch({
headless: headless
});
const page = await browser.newPage();
await page.goto('https://www.mtvema.com/de-de/wahl/bestgermanact/');
// Check if voting buttons are visible
await page.waitForFunction(() => {
const buttons = document.querySelectorAll('.elements-accordion-components-item-styles_button_Nae_sr9iGBxv0mK2bG9iD.sc-bZQynM.etYaFo');
return buttons.length > 0;
});
const selector = 'div.elements-accordion-components-item-styles_item_3UqYKLNwlTA3-XlJkgIjHA:nth-child(4) > .elements-accordion-components-item-styles_button_Nae_sr9iGBxv0mK2bG9iD';
// Check if we have selected the correct button (style it pink)
log(`🕵️Check if we have selected the right element`);
await page.waitForFunction((selector) => {
const button = document.querySelector(selector);
// Change color to make sure we have selected the right button
button.style.background = 'deeppink';
return button !== null && button.parentElement.querySelectorAll('img')[0].alt === 'Fynn Kliemann';
}, selector);
log(`✅ ${chalk.green('Found button for Fynn')}`);
await page.click(selector);
log(`🎉 ${chalk.cyan('Vote for Fynn')} ${chalk.underline('#javascriptfürfynn')} ${chalk.underline('#ventilatorfürfynn')}`);
await page.waitForTimeout(1000);
console.log('------------------------------------------------------');
browser.close();
main();
}
main(false);