Puppeteer:由 ID returns 未定义选择的输入字段
Puppeteer: input field selected by ID returns undefined
在上面,您可以看到带有 #account_email
选择器的输入元素。但是,等待在此字段中进行选择和输入的开玩笑功能测试每次都会失败。我不明白为什么。
下面有语法错误吗?这种选择容易出错吗?欢迎提出任何解决此问题的建议。
// A functonal test file being run by jest.js
// jest-puppeteer
test('[functional] log into shopify"', async () => {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
// go to login page
await page.goto("https://partners.shopify.com/1185756/apps/3207477/test", {waitUntil : "load"});
console.log(page.url, `=====arrived at shopify login screen=====`);
// fill and submit form
const emailInput = await page.focus("#account_email");
await emailInput.type(process.env.SHOPIFY_PARTNER_EMAIL);
// error seen in terminal
TypeError: Cannot read property 'type' of undefined
22 | // email screen
23 | const emailInput = await page.focus("#account_email");
> 24 | await emailInput.type(process.env.SHOPIFY_PARTNER_EMAIL);
| ^
25 |
//
focus
没有 return 元素句柄。你可以这样做:
const emailInput = await page.waitForSelector("#account_email");
await emailInput.focus();
await emailInput.type(process.env.SHOPIFY_PARTNER_EMAIL);
在上面,您可以看到带有 #account_email
选择器的输入元素。但是,等待在此字段中进行选择和输入的开玩笑功能测试每次都会失败。我不明白为什么。
下面有语法错误吗?这种选择容易出错吗?欢迎提出任何解决此问题的建议。
// A functonal test file being run by jest.js
// jest-puppeteer
test('[functional] log into shopify"', async () => {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
// go to login page
await page.goto("https://partners.shopify.com/1185756/apps/3207477/test", {waitUntil : "load"});
console.log(page.url, `=====arrived at shopify login screen=====`);
// fill and submit form
const emailInput = await page.focus("#account_email");
await emailInput.type(process.env.SHOPIFY_PARTNER_EMAIL);
// error seen in terminal
TypeError: Cannot read property 'type' of undefined
22 | // email screen
23 | const emailInput = await page.focus("#account_email");
> 24 | await emailInput.type(process.env.SHOPIFY_PARTNER_EMAIL);
| ^
25 |
//
focus
没有 return 元素句柄。你可以这样做:
const emailInput = await page.waitForSelector("#account_email");
await emailInput.focus();
await emailInput.type(process.env.SHOPIFY_PARTNER_EMAIL);