硒-不要等到所有元素都显示完为止 [英] Selenium - don't wait until all elements are presented

查看:93
本文介绍了硒-不要等到所有元素都显示完为止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,硒正在等待所有元素被加载.有什么方法可以等待特定元素然后继续进行吗? 在我的测试中,selenium正在使用wait()函数等待页面加载.有时,某些图像无法从远程服务器加载,而页面上的所有其他元素均已成功加载.我如何要求Selenium忽略等待特定元素之外的所有元素?

Selenium by default is waiting for all elements to be loaded. Is there any way for waiting for a specific element and then to proceed on? On my test, selenium is waiting with the wait() function for a page to be loaded. sometimes, some images couldn't be loaded from a remote server, while all others element on the page loaded successfully. How can I ask Selenium to ignore waiting all elements except a specific one?

推荐答案

Selenium在页面源代码的副本上工作,因此它尝试等待DOM代表页面完整源代码.为了使它正常工作,硒基于document.readyState:

Selenium works on a copy of the page's source so it try to wait until the DOM represents what will be the page's full source. For this to work correctly selenium is bases on the document.readyState:

  • 未初始化,正在加载,正在加载(正在等待)
  • 交互式,完整(有效).

此行为是工作所必需的,否则可能会发生以下情况并破坏测试:

this behavior is mandatory for work, otherwise the next scenarios might occur and break tests:

  1. 不返回的Ajax请求.
  2. 访问未就绪的元素可能会导致过时的元素异常.

这篇关于硒-不要等到所有元素都显示完为止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆