当前位置:首页 > Python > 正文内容

python-selenium弹框处理driver.switch_to.alert

lonely4年前 (2021-06-24)Python1224

三种弹出框alert(一个按钮),confirm(两个确认,取消),prompt(两个按钮+输入框)


 使用示例:

ele_alert = driver.switch_to.alert    # 切换到弹框
msg = ele_alert.text           # 获取到弹框中的内容
print(msg)
ele_alert.accept()             # 点击弹框中的确定

# 其他
ele_alert.dimiss()             # 点击取消
ele_alert.send_keys('你好')         # 输入内容,prompt弹框才能输入字符


弹框的方法:

driver.switch_to.alert.text
driver.switch_to.alert.accept()
driver.switch_to.alert.dimiss()
driver.switch_to.alert.send_keys()

注意:

调用方法时,switch_to.alert后面不要加括号,例如不要写成switch_to.alert().accept(),否则没有效果。

调用text属性时,不要加括号,例如不要写成switch_to.alert.text(),否则也获取不到文本

扫描二维码推送至手机访问。

版权声明:本文由复制者发布,如需转载请注明出处。

本文链接:https://www.copyer.cn/post/12.html

分享给朋友:

相关文章

将print输出的内容保存到txt文件中

将print输出的内容保存到txt文件中

# 将print输出的内容保存到txt文件中 class Logger(object):     def __init__...

返回当前时间及格式化已使用时间

返回当前时间及格式化已使用时间

import time import datetime # 格式化输出使用时间 class Farmat_time():   &...

python获取基础路径供其他模块导入

python获取基础路径供其他模块导入

# 文件1:获取基础路径,供其他文件导入,当前文件是conf/settings.py文件 import os base_path = os.path.d...

详解python的xlwings库读写excel操作总结

详解python的xlwings库读写excel操作总结

 一、总结一句话总结:xlwings 是 Python 中操作Excel的一个第三方库,支持.xls读写,.xlsx读写,操作非常简单,功能也很强大1、xlwings 中的逻辑:应用->...

python使用国内镜像源安装更新模块

python使用国内镜像源安装更新模块

由于python更新源速度较慢,且经常更新失败。国内更新源可秒更,以下是配置方法。1、python2.7更新pip命令1python -m pip install --upgrad...

Python pip更换安装源

Python pip更换安装源

常见的镜像源:华为:https://repo.huaweicloud.com/repository/pypi/simple 清华:https://pypi.tuna.tsinghua.edu...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。