webdriver.common.alert

The Alert implementation.

Module Contents

Classes

Alert(self,driver) Allows to work with alerts.
class Alert(driver)

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)
__init__(driver)

Creates a new Alert.

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

Gets the text of the Alert.

dismiss()

Dismisses the alert available.

accept()

Accepts the alert available.

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

send_keys(keysToSend)

Send Keys to the Alert.

Args:
  • keysToSend: The text to be sent to Alert.
authenticate(username, password)

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