我需要做Puppeteer
暂停并等待用户输入username
and password
在继续之前。它是一个nodejs
8.12.0 应用程序。
(async () => {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.goto('https://www.myweb.com/login/');
//code to wait for user to enter username and password, and click `login`
const first_page = await page.content();
//do something
await browser.close();
)}();
基本上程序会停止并等待,直到用户单击login
按钮。是否可以这样做Puppeteer
?或者我还能做什么?
您可以使用page.waitForFunction() https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#pagewaitforfunctionpagefunction-options-args在继续之前等待函数返回真值。
以下函数将等待#username
and #password
在继续之前,字段包含一个值:
await page.waitForFunction(() => {
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
return username.length !== 0 && password.length !== 0;
});
但既然你进入了#username
and #password
你自己,你可以简单地使用:
await page.type('#username', 'username');
await page.type('#password', 'password');
await page.click('#login');
await page.waitForNavigation();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)