Answer the question
In order to leave comments, you need to log in
Why doesn't puppeteer js wait for the selector that is displayed in the browser when parsing?
Good afternoon, there is a small parser on puppeteer.
Perhaps it is important that pages with the jsp extension.
Maybe the loading of dynamic content works in a special way than everywhere else ?!
Steps:
1) Authorization (works out)
2) Transition to the landing page. (works out)
3) Click on the loaded element. (problem) . When the parser browser is launched, the element appears after a negligible amount of time. Then it disappears again and reappears. (I don’t know how to deal with this)
None of the following tricks can save you as an expectation. All options were placed before the selector for the next click. None of the options helped:
1) await page.waitForNavigation();
2) await page.waitForSelector
3)
const sleep = (ms) => new Promise((res) => {
setTimeout(res, ms);
});
sleep(3000)
Код:
const puppeteer = require('puppeteer');
const config = require('./config'); // login, password
const sleep = (ms) => new Promise((res) => {
setTimeout(res, ms);
});
const loginUrl = 'loginUrl';
const craftUrl = 'craftUrl';
(async () => {
const browser = await puppeteer.launch({
headless: false,
args: ['--proxy-server=socks5://127.0.0.1:9050']
});
const page = await browser.newPage();
await page.goto(loginUrl);
await page.$eval('#usernameField', (elem, login) => {
elem.value = login;
}, config.login);
await page.$eval('#passwordField', (elem, password) => {
elem.value = password;
}, config.password);
await page.click('#ButtonBox > .OraButton.left');
await page.waitForNavigation();
await page.goto(craftUrl);
sleep(2000);
await page.waitForSelector('.textdiv').then(() => {
let elements = document.getElementsByClassName('textdiv');
elements[0].click()
});
sleep(5000);
await browser.close();
})();
Answer the question
In order to leave comments, you need to log in
await page.waitForSelector('.textdivresp').then(() => {
console.log('textdivresp_ololo');
});
await page.evaluate(() => {
let elements = document.getElementsByClassName('textdivresp');
elements[1].click()
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question