Reputation: 11
I am using WebDriver(Eclipse -Java) to automate a Registration page. On clicking the 'Register' button, a 'success message' is displayed and need to validate the same.
I can do this successfully in IE8. But not able to validate the same in Firefox. I have tried different waits 1. d1.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
WebDriverWait wait = new WebDriverWait(driver, 10); wait.withTimeout(30, TimeUnit.SECONDS); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("ElmId"));
Wait wait = new FluentWait wait = new FluentWait(d1).withTimeout(60, SECONDS); wait.until(new Function() wait.until(ExpectedConditions.visibilityOf(d1.findElement(By.id("elementid"))));
Has anyone faced similar issues? Any solution?
Upvotes: 1
Views: 2771
Reputation: 4099
This 'success message' after clicking a button: is it displayed with ajax/javascript or do you reload a page?
In case you're doing it with js it may be sometimes impossible to verify the message with WebDriver command and you will need to use js for verification too. Something like:
Object successMessage = null;
int counter = 0;
while ((successMessage == null) && counter < 5)
{
try
{
((JavascriptExecutor)driver).executeScript("return document.getElementById('yourId')");
}
catch (Exception e)
{
counter +=1;
}
}
if (successMessage != null) //would be better to use some assertion instead of conditional statement
{
//OK
}
else
{
//throw exception
}
The while loop is ugly way for pseudo-wait functionality. You may as well remove it if you don't need to wait for element.
The alternative could be
Object result = ((JavascriptExecutor)driver).executeScript("return document.body.innerHtml");
String html = result.toString();
and then parsing html manually.
Upvotes: 0
Reputation: 2021
Maybe you could try with other conditions types? Or you could also try writing your own by overriding the apply method. I had few cases when using the provided conditions was not enough. Only after using my own version of apply method it was successfull.
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(timeoutInSeconds, TimeUnit.SECONDS)
.pollingEvery(pollingInterval,
TimeUnit.MILLISECONDS);
return wait.until(new ExpectedCondition<WebElement>() {
@Override
public WebElement apply(WebDriver arg0) {
List<WebElement> findElements = driver.findElements(By.className(someClassName));
for (WebElement webElement : findElements) {
if (webElement.getText().equals(string)) {
return webElement;
}
}
return null;
}
});
e. g. something like this was pretty helpful few times.
Upvotes: 0