I have created the following method:
public void waitAndClickElement(WebElement element) throws InterruptedException {
try {
Boolean elementPresent = this.wait.until(ExpectedConditions.elementToBeClickable(element)).isEnabled();
if (elementPresent == true && element.isDisplayed()) {
element.click();
System.out.println("Clicked on the element: " + element.getText());
}
} catch (StaleElementReferenceException elementUpdated) {
Boolean elementPresent = wait.until(ExpectedConditions.stalenessOf(element));
if (elementPresent == true) {
WebElement staleElement = element;
staleElement.click();
System.out.println("Clicked on the 'Stale' element: " + element.getText());
}
} catch (NoSuchElementException e) {
System.out.println("Exception! - Could not click on the element: " + element.getText() + ", Exception: "+ e.toString());
throw (e);
} finally {
}
}
But I Still seem to get the following exception below:
Expected condition failed: waiting for element (Proxy element for: DefaultElementLocator 'By.xpath: //a[text()='Exchange Now »']') to become stale (tried for 20 second(s) with 500 MILLISECONDS interval)
But the same method will work on let's say 18 out of 20 builds, any ideas?
thanks for you help