[英]How to implement AjaxElementLocatorFactory through Selenium and Page Factory?
我使用 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 超時相加。
我在您的代碼試驗中沒有看到任何問題。
AjaxElementLocatorFactory
是頁面工廠模式中的延遲AjaxElementLocatorFactory
概念,用於識別WebElements僅當它們用於任何操作時,即 WebElement 的AjaxElementLocatorFactory
可以在AjaxElementLocatorFactory
的幫助下分配給 Object 頁面類。
句法:
PageFactory.initElements(new AjaxElementLocatorFactory(driver, TimeoutValue), this);
例子:
PageFactory.initElements(new AjaxElementLocatorFactory(driver,5), this);
上面的代碼將等待最多 5 秒,直到加載注釋指定的元素。 如果在給定的時間跨度內未找到該元素,它將拋出NoSuchElementException
。
因此,根據您的代碼塊,如果5 seconds
后未找到該元素,則應拋出NoSuchElementException 。
AjaxElementLocatorFactory使用SlowLoadableComponent創建一個AjaxElementLocator ,當load()
返回時,該組件可能尚未完成加載。 在調用load()
, isLoaded()
方法應該繼續失敗,直到組件完全加載。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.