Đoạn mã dưới đây hoạt động tốt, nhưng tôi đang gặp một chút rắc rối với wait.until()
dòng:Làm thế nào để sử dụng selenium 2 PageStactory init Elements với Wait.until()?
wait.until(new ElementPresent(By.xpath("//a[@title='Go to Google Home']")));
Nó hoạt động nhưng tôi muốn gửi PageFactory
WebElement
homePageLink
thay tôi:
wait.until(new ElementPresent(homePageLink));
Is có cách nào để làm điều đó không?
Các tính năng mới của Selenium 2 bị vướng víu này có đầu óc hơi quay và tôi không thể tìm thấy nhiều tài liệu.
Cảm ơn.
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);
}
}
tôi sử dụng SlowLoadableComponent để thay thế. Nó cho phép tôi đặt sự chậm trễ giữa isLoaded() và load() để trang tiếp tục thử lại cho đến khi trang được tải. – djangofan