随着操纵木偶的铬试验开发工具,我想设置和使用外部FUNC木偶戏:使用外部功能与DOM的互动
const puppeteer = require('puppeteer');
async function setSelectVal(page, sel, val) {
page.evaluate((data) => {
return document.querySelector(data.sel).value = data.val
}, {sel, val})
}
(async() => {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.goto('url', {waitUntil: 'load'});
const inputLogin = await page.$('input[name=login]');
await page.focus('input[name=login]');
await page.type('login', {delay: 100});
const inputPassord = await page.$('input[name=password]');
await inputPassord.click();
await page.type('pass', {delay: 100});
const inputValidate = await page.$('input[name=valid]');
await inputValidate.click();
await page.waitForSelector('td.newpageclass');
await setSelectVal(page, 'select[name=targetname]', 'targetvalue')
})();
,但它触发的错误:
(node:16312) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Protocol error (Runtime.evaluate): Target closed. (node:16312) [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.
你知道我应该怎么做?
没有太多这方面的专家,但好像browser.newPage()失败,做一个尝试捕捉并检查异常,甚至听起来页面为空(即browser.newPage()或者不一个承诺或返回空? – PiniH
@PiniH谢谢fr answere,非newage作品我编辑页面,以显示案件更多细节 –