当前位置:网站首页>Element waiting mechanism
Element waiting mechanism
2022-06-29 18:58:00 【It's Joe Joe】
Background introduction
In many test scenarios , We need to keep the running speed of the script consistent with the response speed of the program . therefore ,WebDriver It provides two mechanisms: implicit waiting and display waiting .
An implicit wait
For solving problems caused by Network delay Or use Ajax Dynamically load elements Resulting in inconsistent program response times , It's very effective .
After setting the implicit wait time ,WebDriver It will continuously detect and search within a certain period of time DOM, To find one or more elements that are not immediately loaded successfully and available .
In general , The default timeout for implicit waiting is set to 0.
self.driver.implicitly_wait(30)
Timeout element not found , It will be thrown out. NoSuchElementException It's abnormal .
According to wait
Display waiting is more controllable than implicit waiting .
Show that waiting can only work on test cases with only synchronous requirements .
WebDriver Provides WebDriverWait Classes and expected_conditions Class to implement display wait .
There are two uses :
WebDriverWait(self.driver, 10).until(lambda s:s.find_element_by_id("select-language").get_attribute("length")=="3")
account = WebDriverWait(self.driver, 10) \
.until(expected_conditions. \
visibility_of_element_located \
((By.LINK_TEXT, "ACCOUNT")))
account.click()
If the timeout , The element is still not visible , It will be thrown out. TimeoutException abnormal .
expected_conditions class
Common waiting conditions are as follows :


Determine whether an element exists
have access to element_to _be_clickable Wait and check if an element is available . When the target element is clickable or available , This method returns the located target element to the test script .
It can also be used as a judgment condition by detecting whether the specified document appears in the title , For example, we can use title_contains Expected condition detection .
Judge whether it exists Alerts
Display wait can also be applied to warnings and page frames .Alert_is_present The expected decision condition can be used to detect whether the warning window appears , And return the warning window to the script , For subsequent actions .
alert = WebDriverWait(self.driver, 10).until(expected_conditions.alert_is_present())
边栏推荐
- Source code installation mavros
- Elegant writing controller (parameter verification + unified exception handling)
- curl下载示例
- The 8th "Internet +" competition - cloud native track invites you to challenge
- MySQL enterprise development specification
- The table ‘table_name‘ is full 异常排查及解决方案
- AMAZING PANDAVERSE:META”无国界,来2.0新征程激活时髦属性
- Data-* attribute usage
- 防汛救援便携式应急通信系统解决方案
- 6.29模拟赛总结
猜你喜欢

Panda Parkour JS games code

关于微服务

centos 7.5安装mysql 8.0.27----yum

Adobe Premiere foundation - batch material import sequence - variable speed and rewind (recall) - continuous action shot switching - subtitle requirements (13)

Adobe Premiere foundation - opacity (mixed mode) (XII)

js文本粒子动态背景

Redis(一)--Redis入门(1)--Redis介绍、安装与启动、常用配置

JS text particle dynamic background

Machine learning 7-Support vector machine
![[how the network is connected] Chapter 3 explores hubs, switches and routers](/img/a9/39f7c474331b7de0bdaf6e59f0d15b.png)
[how the network is connected] Chapter 3 explores hubs, switches and routers
随机推荐
Adobe Premiere foundation - cool text flash (14)
【日常训练】535. TinyURL 的加密与解密
PostGIS generate graphic cut
深度学习---三好学生各成绩所占权重问题(2)
如何将OAK相机当做网络摄像头使用?
layer.prompt
Mac: MySQL 66 questions, 20000 words + 50 pictures!
C Primer Plus 第12章_存储类别、链接和内存管理_代码和练习题
报错[warning] Neural network inference was performed on socket ‘RGB’, depth frame is aligned to socket
Cannot retrieve repository metadata processing records
garbage collector
JS judge whether the array key name exists
Hello, do you have any official website samples for MySQL CDC, PostgreSQL CDC? Give me a link to learn
6.29 simulation summary
PHP 输出两个指定日期之间的所有日期
Us judge ruled that the former security director of Uber accused of covering up hacking must face fraud charges
Leetcode 984. String without AAA or BBB (thought of netizens)
Sd6.23 summary of intensive training
Cannot retrieve repository metadata 处理记录
How to use an oak camera as a webcam?