我正在尝试使用puppeteer登录到Google Auth页面。到目前为止,我已经能够使人偶成功输入用户名,密码和2FA。然后,我被重定向到此Google同意页面
但是,操纵up的人未能单击“允许”按钮并引发以下错误:
typing email...
clicking next button...
waiting for password field...
typing password...
clicking next button...
waiting for consent approval...
clicking Allow button...
(node:87043) UnhandledPromiseRejectionWarning: Error: No node found for selector: #submit_approve_access
at assert (/Users/mohamed/projects/googleAuth/api/src/test/resources/dev-tools/node_modules/puppeteer/lib/helper.js:278:11)
at Frame.click (/Users/mohamed/projects/googleAuth/api/src/test/resources/dev-tools/node_modules/puppeteer/lib/FrameManager.js:736:5)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:189:7)
-- ASYNC --
at Frame.<anonymous> (/Users/mohamed/projects/googleAuth/api/src/test/resources/dev-tools/node_modules/puppeteer/lib/helper.js:144:27)
at Page.click (/Users/mohamed/projects/googleAuth/api/src/test/resources/dev-tools/node_modules/puppeteer/lib/Page.js:973:29)
at doLogin (/Users/mohamed/projects/googleAuth/api/src/test/resources/dev-tools/routes/index.js:177:16)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:189:7)
(node:87043) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:87043) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
下面是我编写的Node.js代码:
async function doLogin(authorizeUrl) {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.goto(authorizeUrl);
await page.mainFrame().waitForSelector('#identifierId');
console.log('typing email...');
await page.type('#identifierId', googleCredentials.username);
await page.mainFrame().waitForSelector('#identifierNext');
console.log('clicking next button...');
await page.click('#identifierNext');
console.log('waiting for password field...');
await page
.mainFrame()
.waitForSelector('#password input[type="password"]', {visible: true});
console.log('typing password...');
await page.type('#password input[type="password"]', googleCredentials.password, {
delay: 100,
});
console.log('clicking next button...');
await page.click('#passwordNext', {delay: 100});
console.log('waiting for consent approval...');
console.log('clicking Allow button...');
await page.click('#submit_approve_access', {delay: 100});
return browser;
}
答案 0 :(得分:3)
单击该按钮尚不可用。可能是这种情况,因为当您单击nvl(birthdate, '0001-01-01')
按钮时,页面将执行异步操作,该操作可能需要几毫秒,可能是网络请求,可能只是一些计算。因此,无需等待,当您致电#passwordNext
时,无需单击任何按钮。
解决方案
您可以在调用page.click
之前添加以下行,以确保该按钮确实存在于页面上:
page.click