当前位置:网站首页>Selenium:元素等待
Selenium:元素等待
2022-08-01 04:59:00 【不怕猫的耗子A】
元素等待
1、前面介绍过,在使用Selenium做Web自动化过程中,可能会因为网络等原因导致页面元素没有加载出来就执行了代码,进而导致报错
⑴特别是在进行元素定位时,经常会遇到元素未加载出来就执行了定位代码,导致报错
2、因此在做Web自动化过程中在合理的地方,设置合理的元素等待时间是非常有必要的。Selenium中提供了3种等待方法
⑴显式等待:WebDriverWait()
⑵隐式等待:implicitly_wait()
⑶强制等待:time.sleep()
显式等待
1、前面有介绍过使用Python中的sleep()方法来进行等待:等待一定的时间,让元素加载出来后再执行代码
⑴但是元素加载出来的时间是不固定的,有时长有时短,因此我们等待的时间就不固定了
⑵最好的办法是:每隔一定的时间后使用Selenium中的一些方法来判断元素是否加载了出来(或其他元素判断)
①元素加载出来了,就不继续等待了
②元素未加载出来,就继续等待
2、显示等待是使WebDriver等待某个条件成立时继续执行,否则在达到最大等待时长时抛出超时异常
⑴最常用的场景:在设置的等待时间内,每隔一定时间检测一次元素是否存在(presence_of_element_located方法)
①如果在设置的时间内找到了元素:则(直接停止等待)往下执行代码
②如果在设
边栏推荐
- typescript27-枚举类型呢
- The difference between scheduleWithFixedDelay and scheduleAtFixedRate
- 请问表格储存中用sql只能查询到主键列,ots sql非主键不支持吗?
- Error: AttributeError: module 'matplotlib' has no attribute 'figure'
- Power button (LeetCode) 212. The word search II (2022.07.31)
- 基于Arduino制作非接触式测温仪
- (2022 Niu Ke Duo School IV) K-NIO's Sword (Thinking)
- 万字逐行解析与实现Transformer,并进行德译英实战(二)
- typescript25 - type assertion
- (2022牛客多校四)K-NIO‘s Sword(思维)
猜你喜欢
C# | 使用Json序列化对象时忽略只读的属性
冲刺金九银十,Android开发面试(内含面试资料|面试题|源码)
Power button (LeetCode) 212. The word search II (2022.07.31)
故乡的素描画
华为Android开发面试后得出的面试秘诀
Logitech Mouse Experience Record
(2022 Nioke Duo School IV) D-Jobs (Easy Version) (3D prefix or)
scheduleWithFixedDelay和scheduleAtFixedRate的区别
typescript23-元组
typescript27 - what about enumeration types
随机推荐
Immutable
ApiFile
pytorch、tensorflow对比学习—计算图和微分机制
scheduleWithFixedDelay和scheduleAtFixedRate的区别
II. Binary tree to Offer 68 - recent common ancestor
[target detection] YOLOv7 theoretical introduction + practical test
25. Have you been asked these three common interview questions?
PAT乙级 1002 写出这个数
(2022牛客多校四)K-NIO‘s Sword(思维)
Pyspark机器学习:向量及其常用操作
LeetCode 231. 2 的幂
API Design Notes: The pimpl trick
typescript21 - Comparison of Interfaces and Type Aliases
Mysql基础篇(约束)
typescript25 - type assertion
typescript27 - what about enumeration types
【堆】小红的数组
7 行代码搞崩溃 B 站,原因令人唏嘘!
Optional parameters typescript19 - object
Error: AttributeError: module 'matplotlib' has no attribute 'figure'