Selenium_python interface-alert Class

Source: Internet
Author: User
Tags http authentication

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.