为什么以下Puppeteer脚本为ExecutionContext.evaluateHandle提供了“未定义”?

时间:2018-10-31 13:15:32

标签: javascript puppeteer

我目前正在学习Puppeteer API,并正在使用v1.9.0。我尝试从iframe中单击按钮时获得以下代码:

const changePrefsFromAllToNone = async () => {

    try {
        const browser = await puppeteer.launch({
            headless:false,
            slowMo: 250});

        const page = await browser.newPage();
        await page.setViewport({width: 1280, height: 800});
        await page.goto(baseUrl);
        await page.waitForSelector('.widget-title');
        const frame = page.frames().find(f => f.name() === 'iframe');
        const prefsDenyButton = await frame.$eval('#option-refuse-phv1L');
        prefsDenyButton.click();

    } catch (error) {
        console.log(error);
    }
};

changePrefsFromAllToNone();

,错误为:

Error: The following is not a function: undefined
at ExecutionContext.evaluateHandle 

我使用的是直接来自puppeteer网站的示例: https://github.com/GoogleChrome/puppeteer/blob/v1.9.0/docs/api.md#

1 个答案:

答案 0 :(得分:0)

您正在寻找query selector,而不是@commands.has_role(name='Admin')。您还错过了eval。这应该起作用:

await