Sample code to create custom wait until element is present inside a parent element.
Method Definition:
protected void waitForElementInParent(final WebElement parent,final By locator,int timeout) {
final WebDriverWait wait = new WebDriverWait(this.driver(), timeout);
wait.until(new ExpectedCondition<WebElement>() {
@Override
public WebElement apply(WebDriver driver) {
try {
return parent.findElement(locator);
} catch (final WebDriverException e) {
// return nothing
return null;
}
}
});
}
How to Call method:
waitForElementInParent(parentElement,By.id("uname"),60);