How to implement AjaxElementLocatorFactory through Selenium and Page Factory?

前端 未结 1 1057
栀梦
栀梦 2021-01-14 01:20

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 Aj

相关标签:
1条回答
  • 2021-01-14 02:17

    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.

    0 讨论(0)
提交回复
热议问题