无法 运行 linkedin sales navigator 上的 puppeteer 脚本

Unable to run the puppeter script on linkeding sales navigator

我正在使用 javascript puppeter 库使用以下代码登录 linkedin sales navigator

const page = await browser.newPage();

                // set larger browser height so that the max of 10 results is shown per page
                page.setViewport({ width: 1280, height: 1200 });
                console.log('page view port setup');

                await page.goto('https://www.linkedin.com/sales/login');

                const EMAIL_SELECTOR = '#username';
                const PASSWORD_SELECTOR = '#password';
                const BUTTON_SELECTOR = '#app__container > main > div > form > div.login__form_action_container > button';

                console.log('clicking page')
                await page.click(EMAIL_SELECTOR);
                await page.keyboard.type(CREDS.linkedin);
                console.log('password change');
                await page.click(PASSWORD_SELECTOR);
                await page.keyboard.type(CREDS.password);

                console.log('click the button');
                await page.click(BUTTON_SELECTOR);

当我执行代码片段时出现错误 但我发现节点存在于 ui

这是因为表单位于 iframe 中。您必须先 select 在 puppeteer 中:

const page = await browser.newPage();

                // set larger browser height so that the max of 10 results is shown per page
                page.setViewport({ width: 1280, height: 1200 });
                console.log('page view port setup');

                await page.goto('https://www.linkedin.com/sales/login');

                const iframe = await (await page.$('iframe')).contentFrame()

                const EMAIL_SELECTOR = '#username';
                const PASSWORD_SELECTOR = '#password';
                const BUTTON_SELECTOR = '#app__container > main > div > form > div.login__form_action_container > button';

                console.log('clicking page')
                await iframe.click(EMAIL_SELECTOR);
                await page.keyboard.type(CREDS.linkedin);
                console.log('password change');
                await iframe.click(PASSWORD_SELECTOR);
                await page.keyboard.type(CREDS.password);

                console.log('click the button');
                await iframe.click(BUTTON_SELECTOR);