I have the following code to select an image using Selenium, only now I have added an errorRecovery
. Is there is a better way to right the code in the catch
?
public static void selectHeader() {
try {
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By
.xpath("//*[contains(@id, 'picture-und-0-select')]")));
driver.findElement(
By.xpath("//a[contains(@id, 'picture-und-0-select')]"))
.click();
driver.switchTo().frame("mediaBrowser");
wait.until(ExpectedConditions.presenceOfElementLocated(By
.linkText("LIBRARY")));
driver.findElement(By.linkText("LIBRARY")).click();
driver.findElement(By.tagName("img")).click();
driver.findElement(By.linkText("Submit")).click();
driver.switchTo().defaultContent();
} catch (UnhandledAlertException alert) {
errorRecovery error = _TestSuite.errorRecovery;
if (error.getCount() == 0) {
error.addCount();
selectHeader();
} else {
error.resetCount();
throw new UnhandledAlertException(alert.toString());
}
}
}