choco-bot
Version:
Whatsapp-bot
44 lines (33 loc) • 1.69 kB
JavaScript
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
// Replace 'YOUR_PAGE_URL' with the actual URL of the page you want to visit
await page.goto('https://www.cognitoforms.com/Themachinery1/VotingPortal');
// Add a delay to ensure the page is fully rendered
await page.waitForTimeout(2000); // Adjust the delay time as needed (e.g., 2000 milliseconds)
// Loop through form fields with class cog-field--1 to cog-field--40
for (let i = 1; i <= 40; i++) {
const selector = `.cog-field--${i} .el-radio__input`; // Assuming the input element of the radio button
const occurrences = await page.$$eval(selector, (elements, searchText) => {
// Count occurrences of the searchText in the selected elements
return elements.reduce((count, element) => {
const label = element.closest('.el-radio__label');
if (label && label.textContent.includes(searchText)) {
count++;
}
return count;
}, 0);
}, 'Ibukun');
if (occurrences > 0) {
console.log(`Field with class cog-field--${i}: Ibukun appears ${occurrences} times`);
// Click on the radio button
await page.click(selector);
// Wait for a moment to observe the changes
await page.waitForTimeout(5000); // Adjust the delay time as needed (e.g., 5000 milliseconds)
}
}
// Wait for a moment to observe the changes before closing the browser
await page.waitForTimeout(50000); // Adjust the delay time as needed (e.g., 5000 milliseconds)
await browser.close();
})();