0

My application triggers an alert notification after submitting a request and I would like to capture the alert message in the notification using playwright. I have tried the following but still it does not work, Any help here would be appreciated:

My application: The alert captured is shown below

The alert message looks like this

The alert message is a sl-alert as shown here

I have tried the following code but it does not work:

   page.onDialog(dialog -> System.out.println(dialog.defaultValue()));
   page.click("zero-button:has-text(\'Submit\') >> visible=true");


   page.onDialog(alert -> System.out.println(alert.defaultValue()));
   page.click("zero-button:has-text(\'Submit\') >> visible=true");


   page.onDialog(dialog -> System.out.println(dialog.message()));
   page.click("zero-button:has-text(\'Submit\') >> visible=true");

   page.onDialog(alert -> System.out.println(alert.message()));
   page.click("zero-button:has-text(\'Submit\') >> visible=true");
Rikki
  • 1
  • 2
  • Posting images in the questions is generally not a good idea. However, as evident from the picture, your transaction message appears under a `shadow-dom`. Have you added code to handle `shadow-dom` in your code? If not you should do that first. – demouser123 Sep 28 '21 at 06:53

1 Answers1

0

page.onDialog will only intercept modal dialogs opened via alert, prompt etc. On your page you have a custom html overlay which won't trigger dialog events. You can do something like page.waitForSelector("sl-alert") to wait for the dialog to show up.

Yury Semikhatsky
  • 2,144
  • 13
  • 12