首页 > 解决方案 > 隐式等待和 AjaxElementLocatorFactory 有什么区别?

问题描述

根据定义,

隐式等待是告诉 Web Driver 在尝试查找一个或多个元素(如果它们不是立即可用的)时轮询 DOM 一段时间。

请参阅隐式等待

WebElement 的超时将在 AjaxElementLocatorFactory 的帮助下分配给 Object 页面类

请参阅AjaxElementLocatorFactory

从上面看,并不清楚隐式等待和 AjaxElementLocatorFactory 之间究竟有什么区别。请解释。

标签: seleniumselenium-webdriverpage-factoryimplicitwaitajax-element-locator-factory

解决方案


隐式等待

隐式等待是一种配置 WebDriver 在尝试查找元素时轮询 DOM 一段时间的方法,如果它们在HTML DOM中不立即可用。默认设置为0。设置后,将为 WebDriver 对象实例的生命周期设置隐式等待。

您可以在以下位置找到一些相关的讨论:


AjaxElementLocatorFactory

AjaxElementLocatorFactory 是在使用类使用页面工厂时实现服务员的关键优势AjaxElementLocatorFactory

AjaxElementLocatorFactory基本上是在页面工厂模式中实现的概念,仅当 WebElement 用于任何操作时才识别它们,即 WebElement 的timeOut可以在AjaxElementLocatorFactory的帮助下分配给 Object 页面类。

  • 一个例子:

    AjaxElementLocatorFactory myFactory = new AjaxElementLocatorFactory(driver, 20);
    PageFactory.initElements(myFactory, this)
    
  • 解释:

    在上面的代码块中,当对元素执行操作时,等待其可见性仅从那一刻开始。如果在给定的时间间隔内没有找到元素,测试用例执行将抛出NoSuchElementException异常。

您可以在如何通过 Selenium 和 Page Factory 实现 AjaxElementLocatorFactory?


推荐阅读