microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
65.65k stars 3.57k forks source link

[BUG] filechooser not being intercepted when the input is inside an iframe #14231

Closed niranjan94 closed 2 years ago

niranjan94 commented 2 years ago

Context:

Code Snippet

import { chromium } from 'playwright';

async function main() {
  const browser = await chromium.launch({
    headless: false,
  });
  const context = await browser.newContext({});

  const page = await context.newPage();
  page.on('filechooser', (fileChooser) => {
    console.log('file chooser has been triggered');
    fileChooser.setFiles([]);
  });

  await page.goto('https://output.jsbin.com/nugolebuce');

  await page
    .frameLocator('iframe')
    .frameLocator('#result')
    .locator('body > div > input[type=file]')
    .click();
}

main();

Describe the bug

As a workaround, I'm able to make it work by setFileChooserInterceptedNoReply on the private channel on any frame navigation within the page.

page.on('framenavigated', async (frame) => {
  frame.page()._channel.setFileChooserInterceptedNoReply({ intercepted: true });
});
niranjan94 commented 2 years ago

Thanks @yury-s for the quick fix :)

ShaneyWaris commented 2 years ago

Sir, @yury-s , is there any way to choose a single folder with playwright when clicking on a div/button?