当前位置:网站首页>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())
边栏推荐
猜你喜欢

AMAZING PANDAVERSE:META”无国界,来2.0新征程激活时髦属性

1. 使用STM32CubeMX建立STM32G030C8T6项目工程

JWT login authentication

Apache Doris basic usage summary

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

细说GaussDB(DWS)复杂多样的资源负载管理手段

75. nearest common ancestor of binary search tree

garbage collector
![Error [warning] neural network information was performed on socket 'RGB', depth frame is aligned to socket](/img/8a/ebad75daa581e22d50dddde49e1fac.jpg)
Error [warning] neural network information was performed on socket 'RGB', depth frame is aligned to socket

JS text particle dynamic background
随机推荐
The table ‘table_name‘ is full 异常排查及解决方案
Shell基本语法--流程控制
JS judge whether the array key name exists
Shell basic syntax -- process control
js将秒转换成“2h30min50s”的格式
74. maximum profit on shares
[Nanjing University] information sharing of the first and second postgraduate entrance examinations
Sd6.24 summary of intensive training
curl下载示例
如何使用物联网低代码平台进行服务管理?
Selenium WebDriver的高级特性
isalpha()方法介绍
74.股票的最大利润
Adobe Premiere foundation - cool text flash (14)
数据仓库模型分层ODS、DWD、DWM实战
2022.6.29-----leetcode.535
报错[warning] Neural network inference was performed on socket ‘RGB’, depth frame is aligned to socket
PHP implementation of sorting two-dimensional arrays by specified key names
1. use stm32cubemx to establish stm32g030c8t6 project
如何在树莓派上使用OAK相机?