你如何在Puppeteer的Flash TextArea中输入文本?



我正在尝试通过Puppeteer自动登录Flash对象。我只需单击即可自动聚焦在 Flash 文本区域,这似乎有效(出现指示您正在键入的垂直闪烁条)。但是,我尝试使用page.keyboard.presspage.keyboard.up/page.keyboard.downpage.keyboard.type,但没有一个成功地在用户名或密码字段中输入文本。此外,我还设置了一段注入的 Javascript 来console.logFlash 对象上每个keypress事件的键名,并且它仅在我专注于 Flash 对象时手动键入时触发。在我尝试使用Puppeteer键盘输入期间,它不会记录任何内容。我的代码如下:

const login = async (page) => {
await page.waitFor(20);
const username = process.env.SIGNIN_USERNAME;
await page.click(500,500); // Select the username field
await page.waitFor(20); // Allow the blinking bar to appear
await page.keyboard.type(username);
for(let char of username) {
await page.keyboard.press(char);
await page.waitFor(20); // So that it appears like a user is typing
}
for(let char of username){
await page.keyboard.down(char);
await page.waitFor(10);
await page.keyboard.up(char);
await page.waitFor(20);
}
await page.type("object",username); // The Flash object is the first object on the page
console.log(username) // The username is logged to the console and is defined
};

此代码不会导致 Flash 文本区域中出现任何文本。但是,正确的用户名将记录到控制台中。

我是否犯了一个错误,或者Puppeteer中是否有一些通用方法,甚至只是在浏览器中Javascript中将文本输入到我缺少的Flash TextArea中?谢谢。

尝试使用更底层的函数,如keyboard.sendCharacter,它不处理keyboard.press的所有奇怪事件处理。

最新更新