下面的代码片段可以正常工作,但是我在使用该wait.until()
行时遇到了一些问题:
wait.until(new ElementPresent(By.xpath("//a[@title='Go to Google Home']")));
它有效,但我想发送我的PageFactory
WebElement
homePageLink
:
wait.until(new ElementPresent(homePageLink));
有没有办法做到这一点?
这些新奇的 Selenium 2 功能让我有点头晕,我找不到太多文档。
谢谢。
public class GoogleResultsPage extends TestBase {
@FindBy(xpath = "//a[@title='Go to Google Home']")
@CacheLookup
private WebElement homePageLink;
public GoogleResultsPage() {
wait.until(new ElementPresent(By.xpath("//a[@title='Go to Google Home']")));
assertThat(driver.getTitle(), containsString("Google Search"));
}
}
public class ElementPresent implements ExpectedCondition<WebElement> {
private final By locator;
public ElementPresent(By locator) {
this.locator = locator;
}
public WebElement apply(WebDriver driver) {
return driver.findElement(locator);
}
}