2020-12-17 12:08:49 -08:00
# 🎭 [Playwright](https://playwright.dev) for Java
2020-10-22 17:45:14 -07:00
2021-03-05 14:32:34 -08:00
[](https://javadoc.io/doc/com.microsoft.playwright/playwright)
[](https://search.maven.org/search?q=com.microsoft.playwright)
2024-08-07 01:54:40 +03:00
[](https://aka.ms/playwright/discord)
2020-12-14 17:52:33 -08:00
2021-03-26 09:41:41 -07:00
#### [Website](https://playwright.dev/java/) | [API reference](https://www.javadoc.io/doc/com.microsoft.playwright/playwright/latest/index.html)
2020-12-17 12:29:36 -08:00
2020-12-17 12:08:49 -08:00
Playwright is a Java library to automate [Chromium ](https://www.chromium.org/Home ), [Firefox ](https://www.mozilla.org/en-US/firefox/new/ ) and [WebKit ](https://webkit.org/ ) with a single API. Playwright is built to enable cross-browser web automation that is **ever-green** , **capable** , **reliable** and **fast** .
| | Linux | macOS | Windows |
| :--- | :---: | :---: | :---: |
2025-08-21 17:09:15 +02:00
| Chromium <!-- GEN:chromium - version --> 140.0.7339.16<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
2025-07-21 11:06:39 -07:00
| WebKit <!-- GEN:webkit - version --> 26.0<!-- GEN:stop --> | ✅ | ✅ | ✅ |
2025-08-21 17:09:15 +02:00
| Firefox <!-- GEN:firefox - version --> 141.0<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
2020-12-17 12:08:49 -08:00
2025-03-17 11:17:28 -07:00
## Documentation
2021-01-19 11:38:10 -08:00
2025-03-17 11:17:28 -07:00
[https://playwright.dev/java/docs/intro ](https://playwright.dev/java/docs/intro )
2021-01-19 11:38:10 -08:00
2025-03-17 11:17:28 -07:00
## API Reference
2020-10-22 17:45:14 -07:00
2025-03-17 11:17:28 -07:00
[https://playwright.dev/java/docs/api/class-playwright ](https://playwright.dev/java/docs/api/class-playwright )
2020-12-18 12:56:36 -08:00
2025-03-17 11:17:28 -07:00
## Example
2020-12-14 18:52:29 -08:00
2023-05-23 18:27:55 -04:00
This code snippet navigates to Playwright homepage in Chromium, Firefox and WebKit, and saves 3 screenshots.
2020-10-22 17:45:14 -07:00
2020-12-14 18:52:29 -08:00
```java
2020-10-22 17:45:14 -07:00
import com.microsoft.playwright.*;
2020-12-03 18:41:46 +01:00
import java.nio.file.Paths;
2020-12-14 18:52:29 -08:00
import java.util.Arrays;
import java.util.List;
2020-10-22 22:41:34 -07:00
2020-12-14 18:52:29 -08:00
public class PageScreenshot {
2021-02-02 02:31:51 +01:00
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
List< BrowserType > browserTypes = Arrays.asList(
2020-12-14 18:52:29 -08:00
playwright.chromium(),
playwright.webkit(),
playwright.firefox()
2021-02-02 02:31:51 +01:00
);
for (BrowserType browserType : browserTypes) {
2021-02-23 12:30:03 -08:00
try (Browser browser = browserType.launch()) {
BrowserContext context = browser.newContext();
Page page = context.newPage();
2023-05-23 18:27:55 -04:00
page.navigate("https://playwright.dev/");
2021-03-05 14:29:41 -08:00
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("screenshot-" + browserType.name() + ".png")));
2021-02-02 02:31:51 +01:00
}
}
2020-12-14 18:52:29 -08:00
}
2020-10-22 17:45:14 -07:00
}
}
```
2025-03-17 11:17:28 -07:00
## Other languages
2020-12-14 18:52:29 -08:00
2025-03-17 11:17:28 -07:00
More comfortable in another programming language? [Playwright ](https://playwright.dev ) is also available in
- [Node.js (JavaScript / TypeScript) ](https://playwright.dev/docs/intro ),
- [Python ](https://playwright.dev/python/docs/intro ).
- [.NET ](https://playwright.dev/dotnet/docs/intro ),