Explicit Wait for PageFactory @Findby

I have a wait command in Java using a css locator and then click on it.

  new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("button.md-primary.md-raised.md-button.md-default-theme"))).click();

      

Now I turned this locator into a pagefactory object which is lp.btnSignIn()

what would be the correct way for this explicit wait and then push? Can I use expected conditions?

This is my PageFactory code:

@FindBy(css="button.md-primary.md-raised.md-button.md-default-theme")
WebElement btnSignIn;

public WebElement btnSignIn() {
    return btnSignIn;
}

      

+3


source to share


2 answers


Solved by changing the value to VisibilityOf:

new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOf(lp.btnSignIn())).click();

      



Be careful as this checks if the element is visible, which it may not be, but it is still in the DOM.

+1


source


It just depends on the lp.btnSignIn () method you return.

Quoting from selenium documentation here

public static ExpectedCondition<WebElement> presenceOfElementLocated(By locator)

      

Waiting to check that the element is present in the page DOM. This does not necessarily mean that the element is visible.

Parameters:

locator - used to find an element



Return:   WebElement after finding it

Hence you can use lp.btnSignIn () only if it returns css locator instead of WebElement

Hence, your btnSignIn () method will be something like this:

public static Locater btnSignIn() {
    return By.cssSelector("button.md-primary.md-raised.md-button.md-default-theme");
}

      

And now you can use expected conditions like below:

new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(lp.btnSignIn())).click()`;

      

0


source







All Articles