gpt4 book ai didi

javascript - Puppeteer:按 ID 选择的输入字段返回未定义

转载 作者:行者123 更新时间:2023-12-02 21:53:45 24 4
gpt4 key购买 nike

enter image description here

在上面,您可以看到带有 #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 不返回元素句柄。你可以这样做:

const emailInput = await page.waitForSelector("#account_email");
await emailInput.focus();
await emailInput.type(process.env.SHOPIFY_PARTNER_EMAIL);

关于javascript - Puppeteer:按 ID 选择的输入字段返回未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60058784/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com