GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Playwright for Java
  • Docs
  • API
  • Java
  • Node.js
  • Python
  • .NET
  • Community
  • Classes
  • APIRequestContext
  • APIResponse
  • Browser
  • BrowserContext
  • BrowserType

This view

  • Original page
  • New address

GeezerVison is showing playwright.dev — FormData | Playwright Java

This is unreleased documentation for Playwright Java Next version.
For up-to-date documentation, see the latest version (stable).
Version: Next

The FormData is used create form data that is sent via APIRequestContext.

import com.microsoft.playwright.options.FormData;
// ...
FormData form = FormData.create()
.set("firstName", "John")
.set("lastName", "Doe")
.set("age", 30);
page.request().post("http://localhost/submit", RequestOptions.create().setForm(form));

Methods​

append​

Added in: v1.44 formData.append

Appends a new value onto an existing key inside a FormData object, or adds the key if it does not already exist. File values can be passed either as Path or as FilePayload. Multiple fields with the same name can be added.

The difference between FormData.set() and FormData.append() is that if the specified key already exists, FormData.set() will overwrite all existing values with the new one, whereas FormData.append() will append the new value onto the end of the existing set of values.

import com.microsoft.playwright.options.FormData;
// ...
FormData form = FormData.create()
// Only name and value are set.
.append("firstName", "John")
// Name and value are set, filename and Content-Type are inferred from the file path.
.append("attachment", Paths.get("pic.jpg"))
// Name, value, filename and Content-Type are set.
.append("attachment", new FilePayload("table.csv", "text/csv", Files.readAllBytes(Paths.get("my-tble.csv"))));
page.request().post("http://localhost/submit", RequestOptions.create().setForm(form));

Usage

FormData.append(name, value);

Arguments

  • name String#

    Field name.

  • value String | boolean | int | Path | Value#

    • setName String

      File name

    • setMimeType String

      File type

    • setBuffer byte[]

      File content

    Field value.

Returns

  • FormData#

create​

Added in: v1.18 formData.create

Creates new instance of FormData.

Usage

FormData.create();

Returns

  • FormData#

set​

Added in: v1.18 formData.set

Sets a field on the form. File values can be passed either as Path or as FilePayload.

import com.microsoft.playwright.options.FormData;
// ...
FormData form = FormData.create()
// Only name and value are set.
.set("firstName", "John")
// Name and value are set, filename and Content-Type are inferred from the file path.
.set("profilePicture1", Paths.get("john.jpg"))
// Name, value, filename and Content-Type are set.
.set("profilePicture2", new FilePayload("john.jpg", "image/jpeg", Files.readAllBytes(Paths.get("john.jpg"))))
.set("age", 30);
page.request().post("http://localhost/submit", RequestOptions.create().setForm(form));

Usage

FormData.set(name, value);

Arguments

  • name String#

    Field name.

  • value String | boolean | int | Path | Value#

    • setName String

      File name

    • setMimeType String

      File type

    • setBuffer byte[]

      File content

    Field value.

Returns

  • FormData#
  • Methods
    • append
    • create
    • set
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.