Class HtmlFileInput

All Implemented Interfaces:
Serializable, Cloneable, DisabledElement, FormFieldWithNameHistory, LabelableElement, SubmittableElement, ValidatableElement, Element, Node

public class HtmlFileInput extends HtmlInput implements LabelableElement
Wrapper for the HTML element "input".
See Also:
  • Method Details

    • getData

      public final byte[] getData()
      Returns the in-memory data assigned to this file input element, if any.
      Returns:
      null if setData(byte[]) hasn't be used
    • setData

      public final void setData(byte[] data)

      Assigns in-memory data to this file input element. During submission, instead of loading data from a file, the data is read from in-memory byte array.

      NOTE: Only use this method if you wish to upload in-memory data; if you instead wish to upload the contents of an actual file, use HtmlInput.setValueAttribute(String), passing in the path to the file.

      Parameters:
      data - the in-memory data assigned to this file input element
    • setDefaultChecked

      public void setDefaultChecked(boolean defaultChecked)
      Sets the default checked state to use when this element gets reset, if applicable. The default implementation is empty; only checkboxes and radio buttons really care what the default checked value is.
      Specified by:
      setDefaultChecked in interface SubmittableElement
      Parameters:
      defaultChecked - the default checked state to use when this element gets reset, if applicable
      See Also:
    • getSubmitNameValuePairs

      public NameValuePair[] getSubmitNameValuePairs()

      Returns an array of NameValuePairs that are the values that will be sent back to the server whenever this element's containing form is submitted.

      THIS METHOD IS INTENDED FOR THE USE OF THE FRAMEWORK ONLY AND SHOULD NOT BE USED BY CONSUMERS OF HTMLUNIT. USE AT YOUR OWN RISK.

      Specified by:
      getSubmitNameValuePairs in interface SubmittableElement
      Overrides:
      getSubmitNameValuePairs in class HtmlInput
      Returns:
      the values that will be sent back to the server whenever this element's containing form is submitted
    • setContentType

      public void setContentType(String contentType)
      Sets the content type value that should be sent together with the uploaded file. If content type is not explicitly set, HtmlUnit will try to guess it from the file content.
      Parameters:
      contentType - the content type (null resets it)
    • getContentType

      public String getContentType()
      Gets the content type that should be sent together with the uploaded file.
      Returns:
      the content type, or null if this has not been explicitly set and should be guessed from file content
    • getValue

      public String getValue()
      Overrides:
      getValue in class HtmlInput
      Returns:
      the value
    • setDefaultValue

      public void setDefaultValue(String defaultValue)
      Sets the default value to use when this element gets reset, if applicable.
      Specified by:
      setDefaultValue in interface SubmittableElement
      Overrides:
      setDefaultValue in class HtmlInput
      Parameters:
      defaultValue - the default value to use when this element gets reset, if applicable
      See Also:
    • setValue

      public void setValue(String newValue)
      Sets the value.
      Overrides:
      setValue in class HtmlInput
      Parameters:
      newValue - the new value
    • setFiles

      public void setFiles(File... files)
      Used to specify multiple files to upload.

      We may follow WebDriver solution, once made, see https://code.google.com/p/selenium/issues/detail?id=2239

      Parameters:
      files - the list of files to upload
    • setDirectory

      public void setDirectory(File directory)
      Used to specify the upload directory.
      Parameters:
      directory - the directory to upload all files
    • getFiles

      public File[] getFiles()
      Returns the files.
      Returns:
      the array of Files
    • isValid

      public boolean isValid()
      Returns whether this element satisfies all form validation constraints set.
      Overrides:
      isValid in class HtmlInput
      Returns:
      whether this element satisfies all form validation constraints set
    • adjustValueAfterTypeChange

      protected void adjustValueAfterTypeChange(HtmlInput oldInput, BrowserVersion browserVersion)
      Overrides:
      adjustValueAfterTypeChange in class HtmlInput