question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Select file does not work if type="file" element has display:none property

See original GitHub issue

Current behavior

I’m getting

Timed out retrying after 15000ms: cy.selectFile() failed because this element is not visible:

If my element has

style="display: none"

While cypress-file-upload had no issues with that.

{force: true} does not help.

Desired behavior

No response

Test code to reproduce

Just run selectFile

Cypress Version

9.3

Other

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
BlueWindscommented, Jan 19, 2022

So we have a unit test covering this, which you can see here: https://github.com/cypress-io/cypress/blob/develop/packages/driver/cypress/integration/commands/actions/selectFile_spec.js#L459 https://github.com/cypress-io/cypress/blob/develop/packages/driver/cypress/fixtures/files-form.html#L33

My guess is that you’re setting {force: true} on the first argument, rather than the second.

// Correct!
cy.get('#hidden').selectFile({ contents: '@foo' }, { force: true })

// Incorrect!
cy.get('#hidden').selectFile({ contents: '@foo', force: true })

This is something we could have made more explicit in the migration guide. Basically - the first argument is the file/files being uploaded (file name, contents), and the second argument configures how the command behaves (force, action, timeout).

If you’re still seeing an issue after verifying this, a reproducible example and a more detailed report would help us track down what’s going on.

1reaction
BlueWindscommented, Jan 19, 2022

I have something like:

    cy.get("input[type=file]").selectFile("cypress/test-data/test.csv", {
      action: "select",
      force: true,
    });

With force: true this does find the element, but I get an exception thrown:

This sounds like a separate issue, likely related to reading the file from disk; I’d suggest opening a new ticket, and most importantly, provide a reproducible example. A complete test, preferably using a fork of https://app.circleci.com/pipelines/github/cypress-io/cypress-test-tiny will help us help you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Input type file not working if hidden - Stack Overflow
I want to customize my input type file button. For that I have put it inside a span and set its visibility to...
Read more >
<input type="file"> - HTML: HyperText Markup Language | MDN
A file input's value attribute contains a string that represents the path to the selected file(s). If no file is selected yet, the...
Read more >
How to check input file is empty or not using JavaScript/jQuery
Approach 1: Use element.files.length property to check file is selected or not. If element.files.length property returns 0 then the file is ...
Read more >
Lesson 5: Using Javascript to Hide and Show Content
display : none;. Now refresh your page in your browser. What happened? If everything worked properly, your clock should no longer be visible....
Read more >
Styling & Customizing File Inputs the Smart Way - Codrops
Interesting thing is that, if it is a file input, it works out as a click ... such as display: none or visibility:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found