3

I'm looking for solution in page factory to wait.

I don't want to use something like Implicit wait, but something like Explicit.

I read about AjaxElementLocatorFactory, but I'm not sure that it works like Implicit or Explicit. So can anyone help me in knowing how it works and how to use it?

2
  • Why not use the explicit wait itself? Commented Feb 1, 2016 at 14:16
  • becouse i wrote somewhere that in page factory there is no possible to use Explicit
    – BV360
    Commented Feb 1, 2016 at 15:51

2 Answers 2

3

It uses an Explicit Wait, not implicit in the AjaxElementLocatorFactory. Though, it is not the same as the FluentWait that is used elsewhere.

The factory creates an AjaxElementLocator. It uses a SlowLoadableComponent to initiate the wait, which can be found in the get function.

To answer the comment by FDM on NarendraC's answer:

Can you elaborate when you say the code will wait for 15 seconds? Is this from the moment you call any method on an element, for that element only?

Yes, it will wait up to 15 seconds for each element ANYTIME they are accessed. AjaxElementLocator ignores the CacheLookup tag. Skipping over a lot of the PageFactory internals, this can be evident in the LocatingElementHandler. It will call locator.findElement() on each element which will trigger the findElement in the AjaxElementLocator which triggers the wait in the SlowLoadableComponent.

0

I use PageFactory with AjaxElementLocatorFactory - PageFactory is a support class for the Selenium 2 Page Objects pattern which you are using, and the AjaxElementLocatorFactory is the factory for the element locators. In your case the constructor will looks like:

public GoogleResultsPage() { 
    PageFactory.initElements(new AjaxElementLocatorFactory(driver, 15), this);
}

This code will wait maximum of 15 seconds until the elements specified by annotations will appear on the page, in your case the homePageLink which will be located by xpath. You will not need to use ElementPresent class.

AjaxElementLocatorFactory uses SlowLoadableComponent internally.

1
  • Can you elaborate when you say the code will wait for 15 seconds? Is this from the moment you call any method on an element, for that element only?
    – FDM
    Commented Oct 10, 2016 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.