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();
}
}
}
方法
关闭
Added in: v1.9终止此Playwright实例,如果所有创建的浏览器仍在运行,也将关闭它们。
用法
Playwright.close();
创建
Added in: 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
(optional)
返回
属性
chromium()
Added before v1.9该对象可用于启动或连接到Chromium,返回Browser的实例。
用法
Playwright.chromium()
返回
firefox()
Added before v1.9该对象可用于启动或连接到Firefox,返回Browser的实例。
用法
Playwright.firefox()
返回
request()
Added in: v1.16提供可用于Web API测试的API接口。
用法
Playwright.request()
返回
selectors()
Added before v1.9选择器可用于安装自定义选择器引擎。更多信息请参阅extensibility。
用法
Playwright.selectors()
返回
webkit()
Added before v1.9该对象可用于启动或连接到WebKit,返回Browser的实例。
用法
Playwright.webkit()
返回