Playwright
Playwright 模块提供了一种启动浏览器实例的方法。以下是用 Playwright 驱动自动化的典型示例
import com.microsoft.playwright.*;
public class Example {
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
BrowserType chromium = playwright.chromium();
Browser browser = chromium.launch();
Page page = browser.newPage();
page.navigate("http://example.com");
// other actions...
browser.close();
}
}
}
方法
close
添加到:v1.9终止此 Playwright 实例,如果创建的浏览器仍在运行,也将关闭它们。
用法
Playwright.close();
create
添加到:v1.10启动新的 Playwright 驱动程序进程并连接到它。 Playwright.close() 应该在不再需要该实例时调用。
Playwright playwright = Playwright.create();
Browser browser = playwright.webkit().launch();
Page page = browser.newPage();
page.navigate("https://www.w3.org/");
playwright.close();
用法
Playwright.create();
Playwright.create(options);
参数
options
Playwright.CreateOptions
(可选)
返回值
属性
chromium()
添加到:v1.9 之前此对象可用于启动或连接到 Chromium,返回 Browser 的实例。
用法
Playwright.chromium()
返回值
firefox()
添加到:v1.9 之前此对象可用于启动或连接到 Firefox,返回 Browser 的实例。
用法
Playwright.firefox()
返回值
request()
添加到:v1.16公开可用于 Web API 测试的 API。
用法
Playwright.request()
返回值
selectors()
添加到:v1.9 之前选择器可用于安装自定义选择器引擎。有关更多信息,请参阅 可扩展性。
用法
Playwright.selectors()
返回值
webkit()
添加到:v1.9 之前此对象可用于启动或连接到 WebKit,返回 Browser 的实例。
用法
Playwright.webkit()
返回值