{
  "doc": {
    "id": "api/commands/selectfile",
    "title": "selectFile | Cypress Documentation",
    "description": "Select a file or files in an HTML5 input element or simulate dragging a file or files into the browser in Cypress.",
    "section": "api",
    "source_path": "/llm/markdown/api/commands/selectfile.md",
    "version": "a8fd16711bdda4c7b5645b9717e588ae99ec2470",
    "updated_at": "2026-05-18T17:21:32.047Z",
    "headings": [
      {
        "id": "api/commands/selectfile#selectfile",
        "text": "selectFile",
        "level": 1
      },
      {
        "id": "api/commands/selectfile#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/commands/selectfile#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/commands/selectfile#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/commands/selectfile#yields-learn-about-subject-management",
        "text": "Yields Learn about subject management",
        "level": 3
      },
      {
        "id": "api/commands/selectfile#action",
        "text": "Action",
        "level": 3
      },
      {
        "id": "api/commands/selectfile#select-default",
        "text": "select (default)",
        "level": 4
      },
      {
        "id": "api/commands/selectfile#drag-drop",
        "text": "drag-drop",
        "level": 4
      },
      {
        "id": "api/commands/selectfile#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/commands/selectfile#from-a-file-on-disk",
        "text": "From a file on disk",
        "level": 3
      },
      {
        "id": "api/commands/selectfile#on-a-hidden-input",
        "text": "On a hidden input",
        "level": 3
      },
      {
        "id": "api/commands/selectfile#from-a-fixture",
        "text": "From a fixture",
        "level": 3
      },
      {
        "id": "api/commands/selectfile#from-an-api-response",
        "text": "From an API response",
        "level": 3
      },
      {
        "id": "api/commands/selectfile#processing-data-inside-the-test",
        "text": "Processing data inside the test",
        "level": 3
      },
      {
        "id": "api/commands/selectfile#selecting-multiple-files",
        "text": "Selecting multiple files",
        "level": 3
      },
      {
        "id": "api/commands/selectfile#custom-filename-mimetype-and-lastmodified",
        "text": "Custom fileName, mimeType and lastModified",
        "level": 3
      },
      {
        "id": "api/commands/selectfile#dropping-a-file-on-the-document",
        "text": "Dropping a file on the document",
        "level": 3
      },
      {
        "id": "api/commands/selectfile#notes",
        "text": "Notes",
        "level": 2
      },
      {
        "id": "api/commands/selectfile#existence",
        "text": "Existence",
        "level": 3
      },
      {
        "id": "api/commands/selectfile#default-file-existence-assertion",
        "text": "Default file existence assertion",
        "level": 4
      },
      {
        "id": "api/commands/selectfile#actionability",
        "text": "Actionability",
        "level": 3
      },
      {
        "id": "api/commands/selectfile#the-element-must-first-reach-actionability",
        "text": "The element must first reach actionability",
        "level": 4
      },
      {
        "id": "api/commands/selectfile#rules",
        "text": "Rules",
        "level": 2
      },
      {
        "id": "api/commands/selectfile#requirements-learn-about-chaining-commands",
        "text": "Requirements Learn about chaining commands",
        "level": 3
      },
      {
        "id": "api/commands/selectfile#assertions-learn-about-assertions",
        "text": "Assertions Learn about assertions",
        "level": 3
      },
      {
        "id": "api/commands/selectfile#timeouts-learn-about-timeouts",
        "text": "Timeouts Learn about timeouts",
        "level": 3
      },
      {
        "id": "api/commands/selectfile#command-log",
        "text": "Command Log",
        "level": 2
      },
      {
        "id": "api/commands/selectfile#history",
        "text": "History",
        "level": 2
      },
      {
        "id": "api/commands/selectfile#community-recognition",
        "text": "Community Recognition",
        "level": 3
      },
      {
        "id": "api/commands/selectfile#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "content": {
    "type": "root",
    "children": [
      {
        "type": "heading",
        "depth": 1,
        "children": [
          {
            "type": "text",
            "value": "selectFile"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Selects a file or files in an HTML5 input element or simulates dragging a file or files into the browser."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "It is "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/core-concepts/retry-ability.md#Only-queries-are-retried",
            "children": [
              {
                "type": "text",
                "value": "unsafe"
              }
            ]
          },
          {
            "type": "text",
            "value": " to chain further commands that rely on the subject after `.selectFile()`."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Syntax"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": ".selectFile(file).selectFile(file, options).selectFile([file1, file2, ...]).selectFile([file1, file2, ...], options)"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Usage"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Correct Usage"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.get('input[type=file]').selectFile('file.json')cy.get('input[type=file]').selectFile(['file.json', 'file2.json'])cy.get('input[type=file]').selectFile({  contents: Cypress.Buffer.from('file contents'),  fileName: 'file.txt',  mimeType: 'text/plain',  lastModified: Date.now(),})cy.get('input[type=file]').selectFile('file.json', { action: 'drag-drop' })cy.document().selectFile('file.json', { action: 'drag-drop' })"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Incorrect Usage"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "// Errors, cannot be chained off 'cy'cy.selectFile('file.json')// Will attempt to find a file called 'file contents'// on disk, probably not what you intendedcy.get('input[type=file]').selectFile('file contents')"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Arguments"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "file (String, Array, Object or Cypress.Buffer)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Either a single file, or an array of files. A file can be:"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "A path to a file within the project root (the directory that contains the default Cypress configuration file). Eg: `'path/to/file.json'`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`@alias` - An alias of any type, previously stored using `.as()`. Eg: `'@alias'`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "A "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray",
                    "children": [
                      {
                        "type": "text",
                        "value": "`TypedArray`"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " containing binary data, such as `Uint8Array.from('123')`. "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/utilities/buffer.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`Cypress.Buffer`"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " instances, such as those returned by `cy.readFile('file.json', null)` or created by `Cypress.Buffer.from('foo')` are `TypedArray` instances."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "An object with a non-null `contents` property, specifying details about the file. Eg: `{contents: '@alias', fileName: 'file.json'}`"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "If an object is provided, it can have the following properties."
          }
        ]
      },
      {
        "type": "table",
        "align": [
          null,
          null
        ],
        "children": [
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Option"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Description"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`contents`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "The contents of the file. This can be a string shorthand as described above, a `TypedArray` instance containing binary data (such as a `Cypress.Buffer` instance) or a non-TypedArray object, which will be converted into a string with `JSON.stringify()` and `utf8` encoded."
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`fileName`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "The name of the file. If `contents` is a path on disk or an alias from `cy.readFile()` or `cy.fixture()`, this defaults to the actual filename. In any other case, this defaults to an empty string."
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`mimeType`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "The "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "https://developer.mozilla.org/en-US/docs/Web/API/File/type",
                    "children": [
                      {
                        "type": "text",
                        "value": "mimeType"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " of the file. If omitted, it will be "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "https://github.com/jshttp/mime-types#mimelookuppath",
                    "children": [
                      {
                        "type": "text",
                        "value": "inferred"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " from the file extension. If one cannot be inferred, it will default to an empty string."
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`lastModified`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "The file's last modified timestamp, in milliseconds elapsed since the UNIX epoch (eg. "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime",
                    "children": [
                      {
                        "type": "text",
                        "value": "`Date.prototype.getTime()`"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": "). This defaults to `Date.now()`."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "options (Object)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Pass in an options object to change the default behavior of `.selectFile()`."
          }
        ]
      },
      {
        "type": "table",
        "align": [
          null,
          null,
          null
        ],
        "children": [
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Option"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Default"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Description"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`action`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`'select'`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Switches modes. Valid values are `select` and `drag-drop`. See "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "#Action",
                    "children": [
                      {
                        "type": "text",
                        "value": "Action"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " below for more details."
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`animationDistanceThreshold`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/configuration.md#Actionability",
                    "children": [
                      {
                        "type": "text",
                        "value": "`animationDistanceThreshold`"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "The distance in pixels an element must exceed over time to be "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/interacting-with-elements.md#Animations",
                    "children": [
                      {
                        "type": "text",
                        "value": "considered animating"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": "."
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`force`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`false`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Forces the action, disables "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "#Assertions",
                    "children": [
                      {
                        "type": "text",
                        "value": "waiting for actionability"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": "."
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`log`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`true`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Displays the command in the "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/open-mode.md#Command-Log",
                    "children": [
                      {
                        "type": "text",
                        "value": "Command log"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": "."
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`timeout`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/configuration.md#Timeouts",
                    "children": [
                      {
                        "type": "text",
                        "value": "`defaultCommandTimeout`"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Time to wait for `.selectFile()` to resolve before "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "#Timeouts",
                    "children": [
                      {
                        "type": "text",
                        "value": "timing out"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": "."
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`waitForAnimations`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/configuration.md#Actionability",
                    "children": [
                      {
                        "type": "text",
                        "value": "`waitForAnimations`"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Whether to wait for elements to "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/interacting-with-elements.md#Animations",
                    "children": [
                      {
                        "type": "text",
                        "value": "finish animating"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " before executing the command."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Yields "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/core-concepts/introduction-to-cypress.md#Subject-Management",
            "children": [
              {
                "type": "text",
                "value": "Learn about subject management"
              }
            ]
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.selectFile()` yields the same subject it was given."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "It is "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/retry-ability.md#Only-queries-are-retried",
                    "children": [
                      {
                        "type": "text",
                        "value": "unsafe"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " to chain further commands that rely on the subject after `.selectFile()`."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Action"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Depending on the `action` set in the `options` argument, `.selectFile()` can simulate two different user behaviors:"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "`select` (default)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "By default, `.selectFile()` runs in 'select' mode, mimicking a user selecting one or more files on an HTML5 input element. In this mode, the "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/core-concepts/introduction-to-cypress.md#Subject-Management",
            "children": [
              {
                "type": "text",
                "value": "subject"
              }
            ]
          },
          {
            "type": "text",
            "value": " must be a single `input` element with `type=\"file\"`, or a `label` element connected to an input (either with its `for` attribute or by containing the input)."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "`drag-drop`"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Setting the action to `drag-drop` changes the behavior of the command to instead mimic a user dragging files from the operating system into the browser, and dropping them over the selected subject. In this mode, the subject can be any DOM element or the `document` as a whole."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Examples"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "From a file on disk"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.get('input[type=file]').selectFile('path/to/file.json')cy.get('input[type=file]').selectFile('path/to/file.png')"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "If given a path, `.selectFile()` will search for the file relative to the project root and attach the file exactly as it exists on disk. This is the preferred way to work with files on disk, avoiding many encoding-related pitfalls."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "On a hidden input"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.get('input[type=file]').selectFile('file.json', { force: true })"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "In many cases in modern applications, the underlying file input is hidden from view, and activated by a user clicking on a button. In these cases, you will need to tell Cypress to ignore its actionability checks and select the file even though a user would not be able to directly activate the file input."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "From a fixture"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.fixture('file.json', null).as('myFixture')cy.get('input[type=file]').selectFile('@myFixture')"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Note the use of `null` encoding. By default, `cy.fixture()` and `cy.readFile()` attempt to interpret files read from disk, which would result in a JSON file being decoded and re-encoded as a utf-8 string - the contents would be preserved, but formatting would not be and the encoding might change. See "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/fixture.md",
            "children": [
              {
                "type": "text",
                "value": "`cy.fixture`"
              }
            ]
          },
          {
            "type": "text",
            "value": " or "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/readfile.md",
            "children": [
              {
                "type": "text",
                "value": "`cy.readFile`"
              }
            ]
          },
          {
            "type": "text",
            "value": " for more details on file encoding."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "From an API response"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.request('http://localhost:8888/users/827').its('body').as('responseBody')cy.get('input[type=file]').selectFile('@responseBody')"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Processing data inside the test"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.readFile('users.json')  .then((users) => {    users[0].username = 'JohnCena'  })  .as('myFile')cy.get('input[type=file]').selectFile('@myFile')"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Selecting multiple files"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.get('input[type=file]').selectFile([  'file1.json',  'file2.json',  'file3.json',])"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "This will fail unless the file input has the `multiple` property."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Custom fileName, mimeType and lastModified"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.get('input[type=file][multiple]')  .selectFile([    {      contents: 'cypress/fixtures/example.json',    },    {      contents: 'cypress/fixtures/example.json',      fileName: 'file.png',    },    {      contents: 'cypress/fixtures/example.json',      fileName: 'file.png',      mimeType: 'text/plain',      lastModified: new Date('Feb 18 1989').valueOf(),    },  ])  .then(($input) => {    const files = $input[0].files    // If nothing is specified, the fileName and MIME type will be inferred from the path on disk.:    expect(files[0].name).to.eq('example.json')    expect(files[0].type).to.eq('application/json')    // If the fileName is given, the MIME type will be inferred based on that.    expect(files[1].name).to.eq('file.png')    expect(files[1].type).to.eq('image/png')    // But an explicitly specified MIME type is always used.    expect(files[2].name).to.eq('file.png')    expect(files[2].type).to.eq('text/plain')    // lastModified defaults to the current time, but can be overridden.    expect(files[0].lastModified).to.be.closeTo(Date.now(), 1000)    expect(files[1].lastModified).to.be.closeTo(Date.now(), 1000)    expect(files[2].lastModified).to.eql(new Date('Feb 18 1989').valueOf())  })"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Dropping a file on the document"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.document().selectFile('file.json', { action: 'drag-drop' })"
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Notes"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Existence"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Default file existence assertion"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Whenever resolving a file path, `.selectFile()` asserts that the file exists and will fail if it does not exist. It will retry reading the file if it does not initially exist until the file exists or the command times out."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "// will fail after the defaultCommandTimeout is reachedcy.get('input[type=file]').selectFile('does-not-exist.yaml')"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Actionability"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "The element must first reach actionability"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`.selectFile()` is an \"action command\" that follows all the rules of "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/core-concepts/interacting-with-elements.md",
            "children": [
              {
                "type": "text",
                "value": "Actionability"
              }
            ]
          },
          {
            "type": "text",
            "value": "."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Rules"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Requirements "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/core-concepts/introduction-to-cypress.md#Chains-of-Commands",
            "children": [
              {
                "type": "text",
                "value": "Learn about chaining commands"
              }
            ]
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.selectFile()` requires being chained off a command that yields DOM element(s). With the `input` action (default), it further requires a single `input` element with `type=\"file\"`, or a `label` element attached to one."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "If given a path, `.selectFile()` requires the file must exist."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "If given an alias, `.selectFile()` requires that the subject of the alias must not be `null` or `undefined`."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Assertions "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/core-concepts/introduction-to-cypress.md#Assertions",
            "children": [
              {
                "type": "text",
                "value": "Learn about assertions"
              }
            ]
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.selectFile()` will automatically wait for the element to reach an "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/interacting-with-elements.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "actionable state"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": "."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Timeouts "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/core-concepts/introduction-to-cypress.md#Timeouts",
            "children": [
              {
                "type": "text",
                "value": "Learn about timeouts"
              }
            ]
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.selectFile()` can time out waiting for the element to reach an "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/interacting-with-elements.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "actionable state"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": "."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.selectFile()` can time out waiting for a file to exist on disk or for an alias to resolve."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Command Log"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Select file for input"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.get('.file-input').selectFile(Cypress.Buffer.from('Hello world'))"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The commands above will display in the Command Log as:"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "When clicking on `selectFile` within the command log, the console outputs the following:"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "History"
          }
        ]
      },
      {
        "type": "table",
        "align": [
          null,
          null
        ],
        "children": [
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Version"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Changes"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md#9-4-0",
                    "children": [
                      {
                        "type": "text",
                        "value": "9.4.0"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Support for `TypedArray` and `mimeType` property added. Default `fileName` name is no longer lost when working with aliases."
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md#9-3-0",
                    "children": [
                      {
                        "type": "text",
                        "value": "9.3.0"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`.selectFile()` command added"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Community Recognition"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The `.selectFile()` command draws heavy inspiration from the now-deprecated Cypress File Upload plugin. It was made possible by "
          },
          {
            "type": "link",
            "title": null,
            "url": "https://github.com/abramenal",
            "children": [
              {
                "type": "text",
                "value": "@abramenal"
              }
            ]
          },
          {
            "type": "text",
            "value": " and contributors to the "
          },
          {
            "type": "link",
            "title": null,
            "url": "https://github.com/abramenal/cypress-file-upload#contributors",
            "children": [
              {
                "type": "text",
                "value": "cypress-file-upload"
              }
            ]
          },
          {
            "type": "text",
            "value": " repository."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "See also"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/variables-and-aliases.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "Guide: Variables and Aliases"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/fixture.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`.fixture()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/get.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`.get()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/readfile.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`.readFile()`"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      }
    ]
  },
  "token_estimate": 1755
}