Reputation: 39
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
Upvotes: 1
Views: 635
Reputation: 75
I had a similar issue where the file was uploading correctly, but the code which processed the name of the file was always returning 'undefined'
cy.fixture('validData.json', null).as('validData')
cy.get('input[type="file"]').selectFile('@validData', { force: true })
The solution was to upload the file using the entire path:
cy.get('input[type="file"]').selectFile('cypress/fixtures/validData.json', { force: true });
Upvotes: 0
Reputation: 39
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')
Upvotes: -1
Reputation: 6811
I'm not convinced but you can try to add force
?
cy.get('[type="file"]').selectFile(
"cypress/fixtures/TestPNG.png",
{ force: true }
);
Upvotes: 0