The problem is:
await page.waitForSelector('#wrong');
I guess.
Error says selector can’t be found. if I look directly via Mozilla Firefox I can see the selector in the code. Would it be possible, that this problem results from AJAX? The window (that has the selector) is only visible if I click on a website Button.
I work with a raspberrypi and my Mac book.
const puppeteer = require('puppeteer');
const fs = require('fs');
// Regulärer Ausdruck für deutsche Telefonnummern
(async () => {
const browser = await puppeteer.launch({
executablePath: '/usr/bin/chromium-browser',
headless: true,
args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage', '--disable-gpu']
});
Regexausdruck = (/anzahl/)
const page = await browser.newPage();
for (const link of links) {
try {
console.log(`Besuche Link: ${link}`);
await page.goto(link, { waitUntil: 'domcontentloaded' });
const descriptionText = await page.$eval('#viewad-description-text', el => el.textContent);
const found = descriptionText.match(Regexausdruck);
if (found) {
console.log(`Gefunden!`);
try {
await page.evaluate(() => {
const spans = Array.from(document.querySelectorAll('span'));
const targetSpan = spans.find(el => el.textContent.includes('s-Anze'));
if (targetSpan) {
targetSpan.click();
console.log('Button geklickt.');
}
});
await page.waitForSelector('#wrong');
} catch (err) {
console.error(`Fehler beim Interagieren mit dem Modal auf Seite ${link}:`, err);
}
}
} catch (err) {
console.error(`Fehler beim Verarbeiten des Links ${link}:`, err);
}
}
await browser.close();
})();
The thing I need to click: <label class="wrong"><input id="wrong" type="radio" name="level1Reasons" class="jsx-23972394" value="INCORRECT"> <div class="jsx-9324993">Unpassender Inhalt</div></label>
I had a long conversation with ChatGPT and I’m just more confused than before. I don’t have an other option in my mind as I’m new in the Puppeteer world.