File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ ## method: Page.onceDialog
2+ * langs: java
3+
4+ Adds one-off [ Dialog] handler. The handler will be removed immediately after next [ Dialog] is created.
5+ ``` java
6+ page. onceDialog(dialog - > {
7+ dialog. accept(" foo" );
8+ });
9+
10+ // prints 'foo'
11+ System . out. println(page. evaluate(" prompt('Enter string:')" ));
12+
13+ // prints 'null' as the dialog will be auto-dismissed because there are no handlers.
14+ System . out. println(page. evaluate(" prompt('Enter string:')" ));
15+ ```
16+
17+ This code above is equivalent to:
18+ ``` java
19+ Consumer<Dialog > handler = new Consumer<Dialog > () {
20+ @Override
21+ public void accept (Dialog dialog ) {
22+ dialog. accept(" foo" );
23+ page. offDialog(this );
24+ }
25+ };
26+ page. onDialog(handler);
27+
28+ // prints 'foo'
29+ System . out. println(page. evaluate(" prompt('Enter string:')" ));
30+
31+ // prints 'null' as the dialog will be auto-dismissed because there are no handlers.
32+ System . out. println(page. evaluate(" prompt('Enter string:')" ));
33+ ```
34+
35+ ### param: Page.onceDialog.handler
36+ - ` handler ` <[ function] \( [ Dialog] \) >
37+
38+ Receives the [ Dialog] object, it ** must** either [ ` method: Dialog.accept ` ] or [ ` method: Dialog.dismiss ` ] the dialog - otherwise
39+ the page will [ freeze] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking ) waiting for the dialog,
40+ and actions like click will never finish.
41+
142## method: Playwright.close
243* langs: java
344
You can’t perform that action at this time.
0 commit comments