Source:How can I convert a String to a SecretKey
/**
* Attempts to click on an element multiple times (to avoid stale element
* exceptions caused by rapid DOM refreshes)
*
* @param d
* The WebDriver
* @param by
* By element locator
*/
public static void dependableClick(WebDriver d, By by)
{
final int MAXIMUM_WAIT_TIME = 10;
final int MAX_STALE_ELEMENT_RETRIES = 5;
WebDriverWait wait = new WebDriverWait(d, MAXIMUM_WAIT_TIME);
int retries = 0;
while (true)
{
try
{
wait.until(ExpectedConditions.elementToBeClickable(by)).click();
return;
}
catch (StaleElementReferenceException e)
{
if (retries < MAX_STALE_ELEMENT_RETRIES)
{
retries++;
continue;
}
else
{
throw e;
}
}
}
}