简体   繁体   中英

How do you enter text into a Flash TextArea from Puppeteer?

I am trying to automate login in a Flash object via Puppeteer. I have automated focusing on the Flash TextArea just by clicking, and that seems to work (the vertical blinking bar that indicates that you are typing appears). However, I have tried using page.keyboard.press , page.keyboard.up / page.keyboard.down , and page.keyboard.type , and none successfully enter text into the username or password field. Furthermore, I have set a piece of injected Javascript to console.log the key name of every keypress event on the Flash object, and it only fires when I am manually typing while focused on the Flash object. It does not log anything during my attempts to use Puppeteer keyboard inputs. My code is as follows:

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
};

This code does not result in any text appearing in the Flash TextArea. However, the correct username is logged to the console.

Am I making a mistake, or is there some general way in Puppeteer or even just in browser Javascript to enter text into a Flash TextArea that I'm missing? Thanks.

Try using a more low-level function like keyboard.sendCharacter , which doesn't deal with all the weird event handling of keyboard.press .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM