所以我有一个用例场景,我想检查是否存在某些东西,即安全复选框。如果是,则提示用户输入。我已经有了另一个包含提示但不确定如何实现以将其与此结合起来的包。
var result = await new Promise( function (resolve, reject) {
prompt.get(schema, function (err, result) {
console.log('Command-line input received:');
console.log(' password: ' + result.password);
resolve(result);
reject("error with prompt")
})
});
console.log(result);
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.goto(url);
try {
await page.waitFor("#security", { timeout: 3000 });
// do something if there is a security box
}
catch (e) {
console.error('no security');
}
可以通过使用带有waitFor
的try catch来检查try {
await page.waitFor("#login-form-os-captcha", { timeout: 1000 });
console.log("there is captcha")
}
catch (e) {
console.error('no captcha');
// process.exit(1);
}