Reputation: 2328
I need to remove/delete text in an iFrame via puppeteer. I can do it easily using the page method/object, i.e.
await page.click(cssSelectorInput);
for (let i = 0; i < settings._30; i++) {
await page.keyboard.press('Backspace');
}
The above will remove 30 characters or less from the CSS Selector cssSelectorInput. But, when I try:
// Get the iFrame in Signle Sign On page
const frameHandle = await page.$('iframe[id="sso-iframe"]');
const frame = await frameHandle.contentFrame();
await frame.click(cssSelectorInput);
for (let i = 0; i < settings._30; i++) {
await frame.keyboard.press('Backspace');
}
Yes, I know, looking at the puppeteer, frame.keyboard is not there. So, how can I remove text from an input box via puppeteer?
Upvotes: 0
Views: 2348
Reputation: 13822
This seems OK:
import puppeteer from 'puppeteer';
const browser = await puppeteer.launch({ headless: false, defaultViewport: null });
const html = `
<!doctype html>
<html>
<head><meta charset='UTF-8'><title>Test</title></head>
<body>
<iframe src='data:text/html,<input value="Text">'></iframe>
</body>
</html>`;
try {
const [page] = await browser.pages();
await page.goto(`data:text/html,${html}`);
await page.frames()[1].click('input');
for (let i = 0; i < 4; i++) {
await page.keyboard.press('Backspace');
}
} catch (err) { console.error(err); }
Upvotes: 1