隐式等待和AjaxElementLocatorFactory有什么区别?

时间:2019-11-15 10:18:36

标签: selenium selenium-webdriver page-factory implicitwait ajax-element-locator-factory

每个定义

隐式等待是告诉Web驱动程序在尝试查找一个或多个元素(如果不是立即可用)时轮询DOM一定时间。

请参见Implicit wait

借助AjaxElementLocatorFactory,将WebElement的超时分配给“对象”页面类

请参见AjaxElementLocatorFactory

从上面,尚不清楚隐式wait和AjaxElementLocatorFactory之间到底有什么区别。请解释。

2 个答案:

答案 0 :(得分:1)

隐式等待与整个驱动程序对象有关(并且适用于在驱动程序上下文中执行的所有查找)。当您启动Page类的元素时,将使用AjaxElementLocatorFactory。这样,等待仅与您在Page类中描述的元素有关。

由于AjaxElementLocatorFactory利用了基本查找功能,但仅用一些更灵活的逻辑将其包装起来,因此可能将适用于所有的驱动程序上下文中执行的隐式等待添加到超时中您已经为AjaxElementLocator进行了设置(取决于具体情况)。因此,建议不要混合使用它们,并且通常建议避免使用隐式等待(默认情况下将其设置为0)。

答案 1 :(得分:0)

Implicit Wait

隐式等待是一种配置WebDriver的方法,以便在HTML DOM中无法立即找到元素时尝试在一定时间内轮询DOM。默认设置为 0 。设置后,将在WebDriver对象实例的生存期内设置隐式等待。

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


AjaxElementLocatorFactory

在使用类使用AjaxElementLocatorFactory时,实现Ajax的主要优势之一是AjaxElementLocatorFactory。

AjaxElementLocatorFactory基本上是概念,是在 Page Factory 模式中实现的,用于仅在将WebElement用于任何操作(即 timeOut 用于可通过 AjaxElementLocatorFactory 分配给Object页面类的WebElement。

  • 一个例子:

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

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

  

您可以在How to implement AjaxElementLocatorFactory through Selenium and Page Factory?

中找到相关的讨论