如何通过Selenium和Page Factory实现AjaxElementLocatorFactory? [英] How to implement AjaxElementLocatorFactory through Selenium and Page Factory?
问题描述
我已经使用Pagefactory在Selenium中设置了我的所有页面.问题是测试是动态的,因为某些元素仅存在于某些测试中.从m的理解来看,AjaxElementFactory的工作原理是这样的:
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);
}
但是如果元素OwnershipIndividual在5秒内未找到,则它将引发NoSuchElementException. 我的问题是,尽管我将超时设置为5秒,但仍然需要50-60秒的超时时间.为什么会这样?
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?
推荐答案
在您的代码试用中,我没有看到任何此类问题.
I don't see any issue as such in your code trials.
AjaxElementLocatorFactory
是 Page Factory 模式中的延迟加载概念仅在用于任何操作时才标识 WebElements ,例如,借助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);
以上代码最多等待5秒钟,直到加载由注释指定的元素.如果在给定的时间间隔内未找到该元素,则会抛出NoSuchElementException
.
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
.
因此,按照您的代码块,如果在5 seconds
之后找不到该元素,则应抛出 NoSuchElementException .
So as per your code block, if the element isn't found after 5 seconds
, NoSuchElementException should be thrown.
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.
这篇关于如何通过Selenium和Page Factory实现AjaxElementLocatorFactory?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!