puppeteer - Puppeteer 输入值以输入表单
问题描述
如果表单字段是这样的,我该如何放置数据。
<input type="text" placeholder="Email Address" data-id="emailAddress" autocomplete="email" class="AuthenticationModal__AuthenticationTextInput-li0874-28 kuwMeF WebsiteTextInput-sc-1k4jzwj-3 kZlRsK" value="">
<input type="password" placeholder="Password" data-id="password" autocomplete="current-password" class="AuthenticationModal__AuthenticationTextInput-li0874-28 kuwMeF WebsiteTextInput-sc-1k4jzwj-3 kZlRsK" value="">
尝试使用它但没有用。
await page.type('[data-id="emailAddress"]', 'test_account@gmail.com')
await page.type('[data-id="password"]', '12345678')
await page.screenshot({ fullPage: true, path: 'website.png' })
await browser.close();
test_account@gmail.com 不显示在屏幕截图中。
提前致谢。
注意:我只是一个新手
解决方案
告诉我这段代码是否完美运行。
const emailInput = '[placeholder="Email Address"][autocomplete="email"]'
const emailWords = 'test_account@gmail.com'
await page.waitForSelector( emailInput, { timeout: 0 })
await page.focus(emailInput)
await page.keyboard.type(emailWords)
const passwordInput = 'input[placeholder="Password"][autocomplete="current-password"]'
const passwordWords = '12345678'
await page.waitForSelector( passwordInput, { timeout: 0 })
await page.focus(passwordInput)
await page.keyboard.type(passwordWords)
await page.screenshot({ fullPage: true, path: 'website.png' })
await browser.close()
导航发生后,您当然不能 waitForNavigation 。您可以在单击表单中的提交之前使用 waitForNavigation。不要在这里使用任何 await,因为它已经是一个承诺。
Promise.all([
page.waitForNavigation({ waitUntil: 'networkidle0', timeout: 1000000 })
page.click('input[type="submit"]')
])
类似的东西。告诉我这是否有效。并且不要忘记选择此答案作为正确答案,它非常有效。
推荐阅读
- r - 有没有办法在 r 中获取 excel 文件的内容创建时间?
- sql - Build mini-league table of where everybody is at in the walks
- javascript - How to call Google Tag Manager from Blazor Server
- python - 如何使用 python 套接字连接两台计算机?
- azure - extract a list of all Azure Active Directory users through Powershell within Azure Function App save as csv and then send to ftp site
- react-native - How to increase the clickable area of a nested clickable Text
- angular - 在生成动态表单字段时删除行,始终删除最后一个索引
- python - Why does Python throw IndexError for array insertion problem?
- flutter - Statefull widget not changing data, how to fix that?
- python - Python - web crawling / different result from same code? / requests, bs4 / M1