WaitForElement在PageObject中不起作用

时间:2015-02-17 08:27:48

标签: java selenium webdriver pageobjects

问题是它正在等待很长一段时间的元素并且找不到。并且错误不存在。但是,当我尝试调试元素是找到。 如您所见,我在每种方法中使用WebDriverWait wait = new WebDriverWait(driver, 20);。可能是问题所在。

我有BasicClasses

public class BasicClasses {
    protected WebDriver driver;
    protected LoginPage login;
    protected AccountsPage account;
    protected ContactPage contact;
    protected HomePage home;
    private StringBuffer verificationErrors = new StringBuffer();

    @Before
    public void setup() throws Exception {
        driver = new FirefoxDriver();
        driver.get(Url.loginUrl);
        login = new LoginPage(driver);
        home = new HomePage(driver);
        login.loginAs(Data.usernameLogin, Data.passwordLogin).chooseDealerFromDealerPopUP();
        home.checkIfAccountForTestingIsPresent();
    }

    @After
    public void tearDown() throws Exception {

        driver.quit();
        String verificationErrorString = verificationErrors.toString();
        if (!"".equals(verificationErrorString)) {
            fail(verificationErrorString);
        }
    }

登录页面

public class LoginPage extends Page {
    public LoginPage(WebDriver driver) {
        super(driver);
        // TODO Auto-generated constructor stub
    }

    public  HomePage loginAs(String user, String pass) throws InterruptedException{

            assertEquals("Sign In", driver.findElement(By.xpath(Locator.headerForm)).getText());
            driver.findElement(By.id(Locator.usernameLocatorLogin)).clear();
            driver.findElement(By.id(Locator.usernameLocatorLogin)).sendKeys(user);
            driver.findElement(By.id(Locator.passwordLocatorLogin)).clear();
            driver.findElement(By.id(Locator.passwordLocatorLogin)).sendKeys(pass);
            driver.findElement(By.cssSelector(Locator.submitButtonLoginPage)).click();

            WebDriverWait wait = new WebDriverWait(driver, 20);
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(Locator.selectDealerPopUp)));

            return new HomePage(driver);
    }

Abstact class Page:

public abstract class Page {

    protected WebDriver driver;

    public Page(WebDriver driver) {
        this.driver = driver;

    }

    public WebDriver getWebDriver() {
        return driver;
    }

并测试:

public class AddContactAT extends BasicClasses {

    @Test
    public void testAddContactWithNoAccess() throws Exception {

        contact.addContactWithFullAccess("sss");
}

0 个答案:

没有答案