mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
3.4 KiB
3.4 KiB
method: Page.onceDialog
- langs: java
Adds one-off [Dialog] handler. The handler will be removed immediately after next [Dialog] is created.
page.onceDialog(dialog -> {
dialog.accept("foo");
});
// prints 'foo'
System.out.println(page.evaluate("prompt('Enter string:')"));
// prints 'null' as the dialog will be auto-dismissed because there are no handlers.
System.out.println(page.evaluate("prompt('Enter string:')"));
This code above is equivalent to:
Consumer<Dialog> handler = new Consumer<Dialog>() {
@Override
public void accept(Dialog dialog) {
dialog.accept("foo");
page.offDialog(this);
}
};
page.onDialog(handler);
// prints 'foo'
System.out.println(page.evaluate("prompt('Enter string:')"));
// prints 'null' as the dialog will be auto-dismissed because there are no handlers.
System.out.println(page.evaluate("prompt('Enter string:')"));
param: Page.onceDialog.handler
handler
<[function]([Dialog])>
Receives the [Dialog] object, it must either [method: Dialog.accept
] or [method: Dialog.dismiss
] the dialog - otherwise
the page will freeze waiting for the dialog,
and actions like click will never finish.
method: Playwright.close
- langs: java
Terminates this instance of Playwright, will also close all created browsers if they are still running.
method: Playwright.create
- langs: java
- returns: <[Playwright]>
Launches new Playwright driver process and connects to it. [method: Playwright.close
] should be called when the instance is no longer needed.
Playwright playwright = Playwright.create()) {
Browser browser = playwright.webkit().launch();
Page page = browser.newPage();
page.navigate("https://www.w3.org/");
playwright.close();