Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何通过Selenium和Page Factory实现AjaxElementLocatorFactory?_Java_Selenium_Selenium Webdriver_Page Factory_Ajax Element Locator Factory - Fatal编程技术网

Java 如何通过Selenium和Page Factory实现AjaxElementLocatorFactory?

Java 如何通过Selenium和Page Factory实现AjaxElementLocatorFactory?,java,selenium,selenium-webdriver,page-factory,ajax-element-locator-factory,Java,Selenium,Selenium Webdriver,Page Factory,Ajax Element Locator Factory,我已经使用Pagefactory在Selenium中设置了我的所有页面。问题是测试是动态的,因为一些元素只存在于部分测试中。据我了解,AjaxElementFactory的工作原理如下: PageFactory.initElements(new AjaxElementLocatorFactory(driver,5), this); @FindBy(id="ctl00_DefaultContent_RbIndividual") WebElement OwnershipIndividual; p

我已经使用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秒内没有找到,那么它将抛出一个NoTouchElementException。
我的问题是,尽管我已将超时设置为5秒,但超时仍需要50-60秒。为什么会这样?

在您的代码试用中,我看不到任何这样的问题

AjaxElementLocator工厂 页面工厂模式中的懒散加载概念是否仅在任何操作中使用WebElement时才识别WebElement,即可以借助
AjaxementLocatorFactory
将WebElement的超时分配给对象页面类

  • 语法:

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

    PageFactory.initElements(new AjaxElementLocatorFactory(driver,5), this);
    
上述代码将最多等待5秒钟,直到加载批注指定的元素。如果在给定的时间范围内找不到该元素,它将抛出
NoTouchElementException

因此,根据您的代码块,如果在
5秒之后未找到元素,则应抛出NoTouchElementException


幕后
load()
返回时,使用可能尚未完成加载的创建。调用
load()
后,
isLoaded()
方法应继续失败,直到组件完全加载。

这些都不能回答问题。问题是,
我的问题是,尽管我将超时设置为5秒,但仍然需要50-60秒才能超时。为什么会这样?
您解释了当OP明确指出需要50-60秒时,5秒后应该如何引发异常。50-60秒后引发的超时是多少?您是否也在使用
WebDriverWait
s?@JeffC它与我在创建WebDriver时设置的隐式等待有关。删除隐式等待20秒(不是50-60秒)后,AjaxElementLocatorFactory工作正常。我的猜测是隐式等待会覆盖AjaxElementLocatorFactory使用的显式等待,但这仍然不能解释为什么超时异常会在50秒后而不是20秒或25秒后抛出。文档特别声明不要混合隐式和显式等待,因为超时可能不稳定。听起来这就是你可能看到的。Selenium参与者声明无论如何都不使用隐式等待。我会删除所有隐式等待,并根据需要添加WebDriverWait,正如他们所建议的那样。@ZantAgg我认为这个问题的标题应该更改。