0

Per definition,

An implicit wait is to tell Web Driver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available.

See Implicit wait

Timeout for a WebElement will be assigned to the Object page class with the help of AjaxElementLocatorFactory

See AjaxElementLocatorFactory

From above, it's not clear what exactly the difference between implicit wait and AjaxElementLocatorFactory. Please explain.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Sandeep Nalla
  • 173
  • 2
  • 15

2 Answers2

2

Implicit wait is something that is relevant to the entire driver object (and applicable to all lookups performed in the context of the driver). AjaxElementLocatorFactory is used when you initiate elements of your Page class. So that the waits are only be relevant to the elements which you describe within your Page class.

Since AjaxElementLocatorFactory utilizes the basic lookups but just wraps it with some more flexible logic, implicit wait that is applicable to all the lookups performed within your driver context might be added to the timeouts you have set up for your AjaxElementLocator (depending on the circumstances). Hence it is not recommended to mix them and in general it is recommended to avoid using implicit waits (it is set to 0 by default).

Alexey R.
  • 8,057
  • 2
  • 11
  • 27
  • It seems combination of implicit wait & AjaxElementLocatorFactory causes issue as per the question at [https://stackoverflow.com/questions/54914570/how-to-implement-ajaxelementlocatorfactory-through-selenium-and-page-factory] – Sandeep Nalla Nov 15 '19 at 11:17
  • I believe the issue of OP that you refer to is that AjaxElementLocator is still looks up the element in a regular way but wraps that lookup in a sort of repeatable attempts. Hence each time it attempts to check if the element is loaded it envounters implicit wait that is applied to **all** lookups and adds some sleeps on its own. So it is not recommended to use implicit waits and some custom waits alltogether. – Alexey R. Nov 15 '19 at 11:20
2

Implicit Wait

An implicit wait is the approach to configure the WebDriver to poll the DOM for a certain amount of time when trying to find element/s if they are not immediately available within the HTML DOM. The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instance.

You can find a couple of relevant discussions in:


AjaxElementLocatorFactory

AjaxElementLocatorFactory is one of the key advantage in implementing a waiter when using using the AjaxElementLocatorFactory Class.

AjaxElementLocatorFactory is basically the concept implemented with in Page Factory pattern to identify WebElements only when they are used in any operation i.e. a timeOut for a WebElement which can be assigned to the Object page class with the help of AjaxElementLocatorFactory.

  • An example:

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

    In the above code block, when an operation is performed on an element the wait for its visibility starts from that moment only. If the element is not found in the given time interval, Test Case execution will throw NoSuchElementException exception.

You can find a relevant discussion in How to implement AjaxElementLocatorFactory through Selenium and Page Factory?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352