干货!详解playwright实现自动等待的原理

playwright在执行操作之前对元素执行一系列可操作性检查,以确保这些行动按预期运行。它会自动等待(auto-wait)所有相关检查通过,然后才执行请求的操作。如果所需的检查未在给定的范围内通过timeout,则操作将失败并显示TimeoutError。

一个简单的click操作确认了什么

例如 执行page.click(), Playwright 会确认元素的如下属性

element is Attached to the DOM

element is Visible

element is Stable, as in not animating or completed animation

element Receives Events, as in not obscured by other elements

element is Enabled

确认属性的详细解释

下面就对具体的属性进行解释,在这里直接引入英文

  • Attached

Element is considered attached when it is connected to a Document or a ShadowRoot.

解释一下这个Attached, 表示当前节Element在DOM或者Shadow DOM中。

  • Visible

Element is considered visible when it has non-empty bounding box and does not have visibility:hidden computed style. Note that elements of zero size or with display:none are not considered visible. 简单理解就是页面中可见。

  • Stable

Element is considered stable when it has maintained the same bounding box for at least two consecutive animation frames. 简单理解就是元素在页面中能够稳定展示

  • Enabled

Element is considered enabled unless it is a <button>, <select>, <input> or <textarea> with a disabled property. 简单理解就是元素在页面中可被操控。

  • Editable

Element is considered editable when it is enabled and does not have readonly property set. 简单理解就是元素可被编辑。

  • Receives Events

Element is considered receiving pointer events when it is the hit target of the pointer event at the action point. 简单理解就是当单击位置(10、10)的点时,Playwright检查是否有其他元素(通常是一个覆盖层)将捕获在(10、10)处的单击操作。

下面是对每个操作执行的可操作性检查列表:

 

 我的每一篇文章都希望帮助读者解决实际工作中遇到的问题!如果文章帮到了您,劳烦点赞、收藏、转发!您的鼓励是我不断更新文章最大的动力!

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

测试开发Kevin

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值