Alert class path: from Selenium.webdriver.common.alert import alert
The alert class is primarily a popup action, such as: Get property, confirm, cancel, etc.
Interface content:
From Selenium.webdriver.remote.command Import command
Class Alert (object):
"""
Allows to work with alerts.
Use the 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 ("Does wish to quit?", Alert_text)
"""
def __init__ (self, driver):
"""
Creates a new Alert.
: Args:
-Driver:the Webdriver instance which performs user actions.
"""
Self.driver = Driver
@property
def text (self):
"""
Gets the text of the Alert.
property: Gets the contents of the popup box
@property represents a call with a property
"""
Return Self.driver.execute (Command.get_alert_text) ["Value"]
def dismiss (self):
"""
Dismisses the alert available.
do not agree with the contents of the popup box
"""
Self.driver.execute (Command.dismiss_alert)
def accept (self):
"""
Accepts the alert available.
confirm the contents of the popup box
Usage:: Use
Alert (Driver). Accept () # Confirm a alert dialog.
"""
Self.driver.execute (Command.accept_alert)
def send_keys (self, keystosend):
"""
Send Keys to the Alert.
send content to pop-up box "for pop-up boxes with input"
: Args: Parameter explanation
-Keystosend:the text to is sent to Alert.
"""
Self.driver.execute (Command.set_alert_value, {' Text ': Keystosend})
Def authenticate (self, username, password):
"""
Send the Username/password to a authenticated dialog (like with Basic HTTP Auth).
Implicitly ' clicks OK '
sent username/password Authentication dialog box (such as basic HTTP authentication). ' Click OK '
Usage::
Driver.switch_to.alert.authenticate (' cheese ', ' secretgouda ')
: Args:
-username:string to BES set in the Username section of the dialog
-password:string to BES set in the Password section of the dialog
"""
Self.driver.execute (command.set_alert_credentials, {' username ': username, ' password ':p assword})
Self.accept ()
Selenium_python interface-alert Class