我已经使用Pagefactory在Selenium中设置了所有页面。事情是测试是动态的,因为某些元素只存在于某些测试中。从理解AjaxElementFactory的工作原理如下:
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秒。这是为什么?
我在代码试用中没有看到任何问题。
AjaxElementLocatorFactory
是Page Factory模式中的延迟加载概念,用于仅在WebElements用于任何操作时标识WebElements,即可以在AjaxElementLocatorFactory
的帮助下将WebElement的timeOut分配给Object页面类。
PageFactory.initElements(new AjaxElementLocatorFactory(driver, TimeoutValue), this);
PageFactory.initElements(new AjaxElementLocatorFactory(driver,5), this);
上面的代码将等待最多5秒,直到加载注释指定的元素。如果在给定的时间跨度内找不到该元素,它将抛出NoSuchElementException
。
因此,根据您的代码块,如果在5 seconds
之后找不到该元素,则应抛出NoSuchElementException。
AjaxElementLocatorFactory使用AjaxElementLocator创建一个SlowLoadableComponent,当load()
返回时可能没有完成加载。在调用load()
之后,isLoaded()
方法应该继续失败,直到组件完全加载。