Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find document.activeElement in Puppeteer

i want to autofill a form with puppeteer. I fill out the first input, then click on a button that then creates a new input field that has focus.

How can i select this input? Can i use document.activeElement and how?

  let newActivity = 'button.new_activity'
  await page.waitForSelector(newActivity)
  await page.click(newActivity)

// find active/focused input
await page.type(focusedInput, 'message')

like image 644
triptografik Avatar asked Dec 14 '22 10:12

triptografik


1 Answers

You can use evaluateHandle to get the element handle, and then call the type function on that element.

const el = await page.evaluateHandle(() => document.activeElement);
await el.type('message');
like image 110
hardkoded Avatar answered Dec 21 '22 11:12

hardkoded