Reputation: 27
I am trying to upload a file from fixture but I am facing an issue where the element is getting clicked but the file is not getting uploaded. I tried to implement every possible actions but facing the same issue. Is there any other way to upload the file.
// cy.get('.relative > span').click({force: true})
// cy.wait(5000)
// cy.get('.relative > span').attachFile('file-sample_100kB.docx', {force: true})
// cy.wait(5000)
cy.xpath("//span[text()='Upload a file']").click({force: true})
cy.wait(5000)
cy.xpath("//span[text()='Upload a file']").attachFile('file-sample_100kB.docx', {force: true})
Tried attaching file through fixture. Want to attach a file after clicking the Upload a file element.
Upvotes: 0
Views: 47
Reputation: 91
I don't know which version of Cypress you are using, but since the 9.3.0, you can use the command selectFile to simulate a file selection.
Here you will find an interesting blog post that presents this new feature: https://www.cypress.io/blog/2022/01/19/uploading-files-with-selectfile/
Upvotes: 1