pub struct Dialog { /* private fields */ }Expand description
Dialog represents a browser dialog (alert, confirm, prompt, or beforeunload).
Dialogs are dispatched via the page.on(‘dialog’) event. Dialogs must be explicitly accepted or dismissed, otherwise the page will freeze waiting for the dialog to be handled.
See module-level documentation for usage examples.
Implementations§
Source§impl Dialog
impl Dialog
Sourcepub fn new(
parent: Arc<dyn ChannelOwner>,
type_name: String,
guid: Arc<str>,
initializer: Value,
) -> Result<Self>
pub fn new( parent: Arc<dyn ChannelOwner>, type_name: String, guid: Arc<str>, initializer: Value, ) -> Result<Self>
Creates a new Dialog from protocol initialization
This is called by the object factory when the server sends a __create__ message
for a Dialog object.
Sourcepub fn type_(&self) -> &str
pub fn type_(&self) -> &str
Returns the dialog’s type.
Returns one of:
- “alert” - Simple notification dialog
- “confirm” - Yes/No confirmation dialog
- “prompt” - Text input dialog
- “beforeunload” - Page unload confirmation dialog
See: https://playwright.dev/docs/api/class-dialog#dialog-type
Sourcepub fn message(&self) -> &str
pub fn message(&self) -> &str
Returns the message displayed in the dialog.
See: https://playwright.dev/docs/api/class-dialog#dialog-message
Sourcepub fn default_value(&self) -> &str
pub fn default_value(&self) -> &str
Returns the default value for prompt dialogs.
For prompt dialogs, returns the default input value. For other dialog types (alert, confirm, beforeunload), returns an empty string.
See: https://playwright.dev/docs/api/class-dialog#dialog-default-value
Sourcepub fn page(&self) -> Option<Page>
pub fn page(&self) -> Option<Page>
Returns the Page that owns this dialog.
The dialog’s parent in the protocol object hierarchy is the Page.
See: https://playwright.dev/docs/api/class-dialog#dialog-page
Sourcepub async fn accept(&self, prompt_text: Option<&str>) -> Result<()>
pub async fn accept(&self, prompt_text: Option<&str>) -> Result<()>
Accepts the dialog.
For prompt dialogs, optionally provides text input. For other dialog types, the promptText parameter is ignored.
§Arguments
prompt_text- Optional text to enter in a prompt dialog
§Errors
Returns error if:
- Dialog has already been accepted or dismissed
- Communication with browser process fails
See: https://playwright.dev/docs/api/class-dialog#dialog-accept
Sourcepub async fn dismiss(&self) -> Result<()>
pub async fn dismiss(&self) -> Result<()>
Dismisses the dialog.
For confirm dialogs, this is equivalent to clicking “Cancel”. For prompt dialogs, this is equivalent to clicking “Cancel”.
§Errors
Returns error if:
- Dialog has already been accepted or dismissed
- Communication with browser process fails
See: https://playwright.dev/docs/api/class-dialog#dialog-dismiss