5

I have an iFrame with several items and i want to update a record.

const frame = await page.frames()[1];
const P1_CUSTOM_NAME = await frame.$('#P1_CUSTOM_NAME');
await P1_CUSTOM_NAME.type('MyFavoritCustomer', {delay: 20});

This will not overwrite the field P1_CUSTOM_NAME. Unfortunately it appends the value 'MyFavoritCustomer'.

Any suggestions how i can clear an item value?

bkardol
  • 1,258
  • 1
  • 20
  • 32
Stefan Roess
  • 51
  • 1
  • 2
  • ok, i found a possible solution. async function setSelectVal(sel, val) { frame.evaluate((data) => { return document.querySelector(data.sel).value = data.val; }, {sel, val}) } // updates await setSelectVal('#P1_CUSTOM_NAME', 'Hans'); – Stefan Roess Oct 24 '17 at 10:51
  • Does this answer your question? [How to delete existing text from input using Puppeteer?](https://stackoverflow.com/questions/52631057/how-to-delete-existing-text-from-input-using-puppeteer) – ggorlen Jul 01 '21 at 19:04

1 Answers1

4

Try a triple click to focus and select all.

const frame = await page.frames()[1];
const P1_CUSTOM_NAME = await frame.$('#P1_CUSTOM_NAME');
await P1_CUSTOM_NAME.click({clickCount: 3});
await P1_CUSTOM_NAME.type('MyFavoritCustomer', {delay: 20});
Matt
  • 2,096
  • 14
  • 20