admin管理员组文章数量:1328016
I can't verify if a div exists or not on the page using Puppeteer, and I don't know why... I would like to scope the captcha on the page using this code:
puppeteer
.launch(options)
.then(async (browser) => {
const page = await browser.newPage();
await page.setViewport({ width: 1280, height: 720 });
console.log("[+] Connecting...");
await page.goto(";);
console.log("[+] Connected");
page.waitForNavigation()
if (await page.$('div.recaptcha-checkbox-border') !== null)
console.log('[+] Resolving captcha');
})
.catch((err) => {
console.log(err);
});
But my if is alaways false and I don't know why.
Here is a screenshot of the element scoped manually:
I can't verify if a div exists or not on the page using Puppeteer, and I don't know why... I would like to scope the captcha on the page using this code:
puppeteer
.launch(options)
.then(async (browser) => {
const page = await browser.newPage();
await page.setViewport({ width: 1280, height: 720 });
console.log("[+] Connecting...");
await page.goto("https://www.google./recaptcha/api2/demo");
console.log("[+] Connected");
page.waitForNavigation()
if (await page.$('div.recaptcha-checkbox-border') !== null)
console.log('[+] Resolving captcha');
})
.catch((err) => {
console.log(err);
});
But my if is alaways false and I don't know why.
Here is a screenshot of the element scoped manually:
Share Improve this question edited Jan 14, 2021 at 14:45 Rippo 22.4k14 gold badges80 silver badges117 bronze badges asked Jan 14, 2021 at 7:19 dolor3sh4zedolor3sh4ze 1,1651 gold badge11 silver badges30 bronze badges 3- I think you have to wait for the reCaptcha. – Thomas Sablik Commented Jan 14, 2021 at 7:51
-
But I already make a
page.waitForNavigation()
– dolor3sh4ze Commented Jan 14, 2021 at 7:55 - But you don't know when the reCaptcha is created. – Thomas Sablik Commented Jan 14, 2021 at 8:08
1 Answer
Reset to default 9This script should work
'use strict';
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({ headless : false});
const page = await browser.newPage();
console.log("Opening page");
await page.goto('https://www.google./recaptcha/api2/demo');
console.log("Opened page");
const frame = await page.frames().find(f => f.name().startsWith("a-"));
await frame.waitForSelector('div.recaptcha-checkbox-border');
console.log("Captcha exists!");
await browser.close();
})();
It appears that the captcha is inside an iframe that always starts with name=a-
(however I can't confirm that with my limited testing)
You first need to get the iframe then await for the selector after the iframe has loaded. This is the output, try changing the iframe name or the selector name to see it fail.
本文标签: javascriptWaiting for Google Captcha to be displayed using puppeteerStack Overflow
版权声明:本文标题:javascript - Waiting for Google Captcha to be displayed using puppeteer - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742244759a2439058.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论