我在我的項目中使用了硒頁面對象,並且還使用WebDriverWait等待添加元素。在WebDriverWait中使用Selenium頁面對象模式混合的問題
@FindBy(how = How.ID, using = "username")
private WebElement username;
@FindBy(how = How.ID, using = "password")
private WebElement password;
public void login(String username, String password) {
WebDriverWait waiter = new new WebDriverWait(driver, 5, 200);
waiter.until(ExpectedConditions.presenceOfElementLocated(
By.id("username")));
this.username.sendKeys(username)
}
兩個問題:
因爲我們只需要:
waiter.until(ExpectedConditions.presenceOfElementLocated( By.id("username"))).sendkey(username);
,而不是頁面對象的用戶名來返回你想要的元素,是頁面對象模式無用?
如果頁面對象模式是必須的,我該如何處理字符串「username」?我需要一個新的類保持常量,如:
public final static String USERNAME = "username";
,所以我們可以把它叫做我的網頁上?
希望下面的鏈接回答你的問題 - http://stackoverflow.com/questions/18843581/wait-for-elment-webdriver-pageobject-pattern –