selenium.webdriver.common.alert#

The Alert implementation.

Classes

Alert(driver)

Allows to work with alerts.

class Alert(driver)[source]#

Bases: object

Allows to work with alerts.

Use this class to interact with alert prompts. It contains methods for dismissing, accepting, inputting, and getting text from alert prompts.

Accepting / Dismissing alert prompts:

Alert(driver).accept()
Alert(driver).dismiss()

Inputting a value into an alert prompt:

name_prompt = Alert(driver)
name_prompt.send_keys("Willian Shakesphere")
name_prompt.accept()

Reading a the text of a prompt for verification:

alert_text = Alert(driver).text
self.assertEqual("Do you wish to quit?", alert_text)

Creates a new Alert.

Parameters:

driver – The WebDriver instance which performs user actions.

property text: str#

Gets the text of the Alert.

dismiss()[source]#

Dismisses the alert available.

Return type:

None

accept()[source]#

Accepts the alert available.

Example

Alert(driver).accept() # Confirm a alert dialog.

Return type:

None

send_keys(keysToSend)[source]#

Send Keys to the Alert.

Parameters:

keysToSend (str) – The text to be sent to Alert.

Return type:

None