playwright: [BUG] Filechooser seems to fail for me

Hi, I was trying upload few files using playwright, but it seems to fail for me. I assume I might be doing something wrong.

Details: Playwright Version: 1.6.2 Operating System: Windows 7 Node.js version: 12.18.0 Browser: Firefox

Code:

const {
  firefox
} = require('playwright');
const path = require('path');

// Add youtube email & password
let email = 'xxxxxxx@email.com'
let pass = 'xxxxxxxxxxxx'
let filePath = path.join(__dirname, 'xxxxxxxxxxx.mp4')

async function begin(){
   const browser = await firefox.launch({
        headless: false
      })
     const context = await browser.newContext()
 
    const page = await context.newPage()
    await page.goto('https://www.youtube.com/upload')

    await page.fill('input[type="email"]', email);
    await page.click('text=Next');
    await page.fill('input[type="password"]', pass);
    await page.click('text=Next');
    await page.waitForLoadState();
 await page.on('filechooser', async (fileChooser) => {
     console.log("filechooser called")
      await fileChooser.setFiles(filePath)
  })

  // Button that initiates filechooser event
  await page.click('text=Select files');

}

begin()

Log:

     pw:api <= page.click succeeded +2ms
    filechooser called
      pw:api => elementHandle.setInputFiles started +20ms
      pw:api   navigated to "https://studio.youtube.com/ytscframe" [] +172ms
      pw:api   "domcontentloaded" event fired [] +2ms
      pw:api   "networkidle" event fired [] +498ms
      pw:api <= elementHandle.setInputFiles failed +691ms
     (node:15396) UnhandledPromiseRejectionWarning: Error: elementHandle.setInputFiles: Evaluation failed: NetworkError when attempting to fetch resource.
    
    Note: use DEBUG=pw:api environment variable and rerun to capture Playwright logs.
        at checkException (c:\Users\Nawaz\node_modules\playwright\lib\firefox\ffExecutionContext.js:86:15)
        at FFExecutionContext.evaluateWithArguments (c:\Users\Nawaz\node_modules\playwright\lib\firefox\ffExecutionContext.js:49:9)
        at async evaluateExpression (c:\Users\Nawaz\node_modules\playwright\lib\javascript.js:164:16)
        at async FrameManager.waitForSignalsCreatedBy (c:\Users\Nawaz\node_modules\playwright\lib\frames.js:90:24)
        at async FrameExecutionContext.evaluateInternal (c:\Users\Nawaz\node_modules\playwright\lib\dom.js:36:16)
        at async FFPage.setInputFiles (c:\Users\Nawaz\node_modules\playwright\lib\firefox\ffPage.js:380:9)
        at async c:\Users\Nawaz\node_modules\playwright\lib\dom.js:440:13
        at async FrameManager.waitForSignalsCreatedBy (c:\Users\Nawaz\node_modules\playwright\lib\frames.js:90:24)
        at async ElementHandle._setInputFiles (c:\Users\Nawaz\node_modules\playwright\lib\dom.js:438:9)
        at async c:\Users\Nawaz\node_modules\playwright\lib\dom.js:421:28
      -- ASYNC --
        at ElementHandle.setInputFiles (c:\Users\Nawaz\node_modules\playwright\lib\helper.js:79:23)
        at FileChooser.setFiles (c:\Users\Nawaz\node_modules\playwright\lib\fileChooser.js:35:36)
        at FileChooser.setFiles (c:\Users\Nawaz\node_modules\playwright\lib\helper.js:80:31)
        at Page.<anonymous> (c:\Users\Nawaz\Desktop\playwright\login.js:51:25)
        at Page.emit (events.js:315:20)
        at Page._onFileChooserOpened (c:\Users\Nawaz\node_modules\playwright\lib\page.js:100:14)
    (node:15396) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
    (node:15396) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
      pw:api   "load" event fired [] +9s

Link: https://www.youtube.com/upload

Page Screenshot:

-2020-dec-11-003

Thanks

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (1 by maintainers)

Most upvoted comments

@fawazahmed0 the https://github.com/microsoft/playwright/issues/3496 should be fixed now - so at the very least, Chromium should work fine for this usecase. Could you please verify this?

@fawazahmed0 begin() function is async, please use await begin() to call it. I suppose it should help.

@viraxslot ,hi, I have added the complete code in bug details, you just have to replace the email, password & filePath with appropriate values