1
如何在pageobject字段中使用显式等待? 我有一个pageobject类,我声明字段并使用FindBy标签来实例化它们。我如何添加显式等待如何在selenium webdriver的pageobject字段中使用显式等待?
如何在pageobject字段中使用显式等待? 我有一个pageobject类,我声明字段并使用FindBy标签来实例化它们。我如何添加显式等待如何在selenium webdriver的pageobject字段中使用显式等待?
中声明的部分或全部字段我的解决方案是不使用@FindBy。
在你的页面对象:
By someElementLocator = By.cssSelector(".locator");
public void waitForElementPresent(final By locator, int timeout) {
ExpectedCondition e = new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
return driver.findElements(locator).size() > 0;
}
};
WebDriverWait wait = new WebDriverWait(driver, timeout);
wait.until(e);
}
public WebElement getSomeElement() {
waitForElementPresent(someElementLocator);
return driver.findElement(locator);
}
也许这是一个建筑的问题。我似乎无法找到任何确认@FindBy支持等待的资源,所以它的使用取决于测试设计/体系结构。