1

Attempting to upload a file via a hidden 'input[type="file"]' element.

My code is : Get, Show and Select as per the cypress documentation cy.get('[data-cy="file-input"]').selectFile('cypress/fixtures/myfixture.json')

cy.get('input[type="file"]')
     .invoke('show')                    
     .selectFile('cypress/fixtures/TestPNG.png')`

I'm getting the following. My file is there and I have tried with the full path name from my C:. Same result

enter image description here

2 Answers2

0

I'm not convinced but you can try to add force ?

cy.get('[type="file"]').selectFile(
  "cypress/fixtures/TestPNG.png",
  { force: true }
);
Wandrille
  • 6,267
  • 3
  • 20
  • 43
-1

Here is the answer that worked for me on a hidden input element

  cy.fixture('TestPNG.png').as('myPNG')
                cy.get('input[type=file]')
                    .invoke('show')
                    .selectFile('@myPNG')
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 08 '23 at 06:16