博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Selenium_Python接口-Alert类
阅读量:5294 次
发布时间:2019-06-14

本文共 2052 字,大约阅读时间需要 6 分钟。

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

转载于:https://www.cnblogs.com/yan-xiang/p/6809685.html

你可能感兴趣的文章
关于在头文件中定义变量的问题
查看>>
mybatis学习(二)
查看>>
使用opencv库编译代码并运行
查看>>
Ansible 清单与命令解析(2)
查看>>
SQLServer2008R2评估期已过的解决办法
查看>>
Laravel 开源电商体验与部署
查看>>
总结:iview(基于vue.js的开源ui组件)学习的一些坑
查看>>
django模型相关的知识点
查看>>
【积累篇:他山之石,把玉攻】Mime 类型列表
查看>>
SuperToolTips
查看>>
CircleWaveProgressBar
查看>>
js 闭包
查看>>
表(list)
查看>>
Xamarin 技术解析
查看>>
Django——Ajax
查看>>
在10进制和2进制中,从0到N总共包含1的数目
查看>>
C++大数模板类
查看>>
Javascript 获取dom的宽度 随笔一
查看>>
GBDT总结
查看>>
apache ab的安装步骤
查看>>