4

I've used Pagefactory to set up all of my pages in Selenium. The thing is the test are dynamic in that some elements only exist in some of the test. From m understanding AjaxElementFactory works like this:

PageFactory.initElements(new AjaxElementLocatorFactory(driver,5), this);

@FindBy(id="ctl00_DefaultContent_RbIndividual")
WebElement OwnershipIndividual;

public void sendString(String stuff){
    OwnershipIndividual.sendKeys(stuff);
}

But if the element OwnershipIndividual is not located in 5 seconds then it would throw a NoSuchElementException. My Problem is that although I have set the timeout for 5 seconds it still takes 50-60 seconds to timeout. Why is that?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
ZantAgg
  • 97
  • 3
  • 11
  • 1
    What is the timeout that is thrown after 50-60s? Are you using `WebDriverWait`s also? – JeffC Feb 28 '19 at 21:53
  • 1
    @JeffC It has something to do with the Implicit wait I had set on the creation of the WebDriver. After I deleted the implicit wait which was 20 seconds(not 50-60) the AjaxElementLocatorFactory worked fine. My guess is that Implicit waits override the explicit wait that AjaxElementLocatorFactory uses, but that still doesn't explain why the Timeout Exception is thrown after 50 seconds and not 20 or 25. – ZantAgg Mar 05 '19 at 18:26
  • 4
    The docs specifically state not to mix implicit and explicit waits because timeouts can be erratic. Sounds like this is what you might be seeing. Selenium contributors have stated not to use implicit waits anyway. I would just remove all implicit waits and add WebDriverWait as needed, as they recommend. – JeffC Mar 05 '19 at 21:13
  • @ZantAgg Title of this question should be changed I think. – Sandeep Nalla Nov 15 '19 at 10:30

2 Answers2

1

You might also have provided implicit wait to your driver which is adding up with ur AjaxElementLocatorFactory timeout.

harmeet
  • 11
  • 2
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Pashyant Srivastava Jul 22 '22 at 10:18
0

I don't see any issue as such in your code trials.

AjaxElementLocatorFactory

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

  • Syntax:

    PageFactory.initElements(new AjaxElementLocatorFactory(driver, TimeoutValue), this);
    
  • Example:

    PageFactory.initElements(new AjaxElementLocatorFactory(driver,5), this);
    

The above code will wait for a maximum of 5 seconds until the elements specified by annotations is loaded. If the element is not found in the given time span, it will throw NoSuchElementException.

So as per your code block, if the element isn't found after 5 seconds, NoSuchElementException should be thrown.


Under the hood

The AjaxElementLocatorFactory creates an AjaxElementLocator using a SlowLoadableComponent which might not have finished loading when load() returns. After a call to load(), the isLoaded() method should continue to fail until the component has fully loaded.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 2
    None of this answers the question. The question is, `My Problem is that although I have set the timeout for 5 seconds it still takes 50-60 seconds to timeout. Why is that?` and you explained how after 5 seconds the exception *should* be thrown when OP clearly stated that it takes 50-60s. – JeffC Feb 28 '19 at 21:52