python自动化测试selenium核心技术等待条件教程
作者:aovenus 时间:2022-02-23 15:18:04
Selenium中的鼠标和键盘事件被封装在ActionChains类中,使用方法:
ActionChains(driver).click(btn).perform()
ActionChains中常用方法:
示例网站:http://sahitest.com/demo
示例场景:打开Sahi Tests页面,点击“Alert Test”页面,鼠标点击页面中“Click For Alert”按钮,弹出警告提示框,判断页面是否存在alert,如存在则切换到警告框,并获取警告文本信息,之后点警告框中的确定按钮。
示例脚本:
from selenium import webdriver
from time import sleep
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
class TestWaitCondition(object):
def setup(self):
self.driver = webdriver.Chrome()
self.driver.get("https://sahitest.com/demo/")
def test_waitcondition(self):
#点页面上的Alert Test
self.driver.find_element_by_xpath("/html/body/table/tbody/tr/td[3]/a[1]").click()
#鼠标点击页面中“Click For Alert”按钮
self.driver.find_element_by_name("b1").click()
wait = WebDriverWait(self.driver,2)
#等待并判断警告框是否存在
wait.until(ec.alert_is_present())
#切换到alert页面
alert = self.driver.switch_to.alert
#获取并打印警告框中文本
print(alert.text)
#点弹出警告框中的确定
alert.accept()
self.driver.quit()
运行结果:
以上:来自极客时间课程:selenium自动化测试学习总结。
来源:https://blog.csdn.net/aovenus/article/details/121185584
标签:selenium,自动化测试,等待
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python爬虫之爬取百度音乐的实现方法
2022-09-02 06:22:10
![](https://img.aspxhome.com/file/2023/0/65420_0s.jpg)
Mootools 1.2教程(21)——类(二)
2008-12-28 20:58:00
如何在网页中制作虚线表格
2010-10-20 20:07:00
python自定义函数实现最大值的输出方法
2022-02-07 19:15:28
Python访问MongoDB,并且转换成Dataframe的方法
2022-07-18 20:32:07
如何利用Matplotlib库绘制动画及保存GIF图片
2021-06-08 17:15:40
![](https://img.aspxhome.com/file/2023/7/81677_0s.gif)
Python数学建模StatsModels统计回归模型数据的准备
2021-10-08 09:19:24
![](https://img.aspxhome.com/file/2023/1/79511_0s.png)
一篇文章彻底搞懂Python切片操作
2021-10-11 18:23:07
![](https://img.aspxhome.com/file/2023/5/101575_0s.jpg)
python jinjia2的项目使用
2021-03-16 04:57:21
基于Python数据可视化利器Matplotlib,绘图入门篇,Pyplot详解
2022-11-20 07:59:16
![](https://img.aspxhome.com/file/2023/7/99167_0s.jpg)
搞定web设计中网页路径问题
2007-09-22 08:52:00
Python解析、提取url关键字的实例详解
2023-07-08 11:52:27
![](https://img.aspxhome.com/file/2023/4/76994_0s.jpg)
ORACLE应用经验(2)
2010-07-31 13:31:00
python和flask中返回JSON数据的方法
2023-07-31 02:43:17
![](https://img.aspxhome.com/file/2023/7/94127_0s.jpg)
设计角色的分工和配合
2008-10-20 12:08:00
![](https://img.aspxhome.com/file/UploadPic/200810/20/2008102012945335s.jpg)
YUI学习笔记(4)
2009-03-10 18:25:00
Python使用ffmpy将amr格式的音频转化为mp3格式的例子
2021-06-14 13:50:07
费茨法则在交互设计中的应用
2009-07-09 19:02:00
![](https://img.aspxhome.com/file/UploadPic/20097/9/01-64s.gif)
使用css2.1实现多重背景、多重边框效果[译]
2010-08-23 16:32:00
![](https://img.aspxhome.com/file/UploadPic/20108/23/css2-multiple-background-border-model-12s.png)
采用XML数据来填充ASP表单
2008-05-04 13:32:00