The Alert implementation.

class selenium.webdriver.common.alert.Alert(driver)[source]

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:


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.

Args :
  • driver: The WebDriver instance which performs user actions.

Accepts the alert available.

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

authenticate(username, password)[source]

Send the username / password to an Authenticated dialog (like with Basic HTTP Auth). Implicitly ‘clicks ok’

Usage:: driver.switch_to.alert.authenticate(‘cheese’, ‘secretGouda’)

Args :-username: string to be set in the username section of the dialog -password: string to be set in the password section of the dialog

Dismisses the alert available.


Send Keys to the Alert.

Args :
  • keysToSend: The text to be sent to Alert.

Gets the text of the Alert.

This Page