I have this wait command in Java with a css locator, and then clicks 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 that locator into a pagefactory object which is lp.btnSignIn()
what would be the proper way to issue this explicit wait and then click? Can I still 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;
}
Solved by changing to VisibilityOf:
new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOf(lp.btnSignIn())).click();
Be careful though as this checks if the element is visible, which it might not be, but it is still in a DOM.
It simply depends on what your lp.btnSignIn() method is returning.
Quoting from the selenium documentation here
public static ExpectedCondition<WebElement> presenceOfElementLocated(By locator)
An expectation for checking that an element is present on the DOM of a page. This does not necessarily mean that the element is visible.
Parameters:
locator - used to find the element
Returns: the WebElement once it is located
Hence you could use lp.btnSignIn() only if it's returning the css locater in place of WebElement
Hence your btnSignIn() methos would something like this:
public static Locater btnSignIn() {
return By.cssSelector("button.md-primary.md-raised.md-button.md-default-theme");
}
And now your could use the Expected conditions as below:
new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(lp.btnSignIn())).click()`;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.