• Selenium_Python接口-Alert类


     

    Alert类的路径:from selenium.webdriver.common.alert import Alert

    Alert类主要是一些对弹出框的操作,如:获取属性、确认、取消等

    接口内容:

    from selenium.webdriver.remote.command import Command


    class Alert(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)

    """

    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 表示用属性调用
    """
    return self.driver.execute(Command.GET_ALERT_TEXT)["value"]

    def dismiss(self):
    """
    Dismisses the alert available.
    不同意弹出框的内容
    """
    self.driver.execute(Command.DISMISS_ALERT)

    def accept(self):
    """
    Accepts the alert available.
    确认弹出框的内容

    Usage::用法
    Alert(driver).accept() # Confirm a alert dialog.
    """
    self.driver.execute(Command.ACCEPT_ALERT)

    def send_keys(self, keysToSend):
    """
    Send Keys to the Alert.
    发送内容到弹出框【适用于带输入的弹出框】

    :Args:参数解释
    - keysToSend: The text to be sent to Alert.
    """
    self.driver.execute(Command.SET_ALERT_VALUE, {'text': keysToSend})

    def authenticate(self, username, password):
    """
    Send the username / password to an Authenticated dialog (like with Basic HTTP Auth).
    Implicitly 'clicks ok'
    发送的用户名/密码认证对话框(如基本的HTTP认证)。'点击确定'
    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
    """
    self.driver.execute(Command.SET_ALERT_CREDENTIALS, {'username':username, 'password':password})
    self.accept()

  • 相关阅读:
    CSU 1505: 酷酷的单词【字符串】
    HDU 2036 改革春风吹满地【计算几何/叉乘求多边形面积】
    HDU 2034 人见人爱A-B【STL/set】
    HDU 2031 进制转换
    HDU 1020 Encoding【连续的计数器重置】
    HDU 1999 不可摸数【类似筛法求真因子和】
    动态规划总结
    CSU 1785: 又一道简单题
    CSU 1779: 错误的算法【矩阵/模拟】
    CSU 1777: 大还是小?【模拟/后导0】
  • 原文地址:https://www.cnblogs.com/jiuyigirl/p/7456975.html
Copyright © 2020-2023  润新知