In my application buttons are sometimes obscured by toasts. When I try to click such a button using Selenium - Webdriver I get the following error:
(node:11281) UnhandledPromiseRejectionWarning: WebDriverError: unknown error: Element <button class="md-raised md-primary md-button md-ink-ripple" type="button" ng-transclude="" id="saveButton" ng-click="saveItem($event)">...</button> is not clickable at point (447, 882). Other element would receive the click: <span class="md-toast-text ng-binding" role="alert" aria-relevant="all" aria-atomic="true">...</span>
For Java I see that there is this solution to determine if a button is clickable:
public static boolean isClickable(WebElement el, WebDriver driver)
{
try{
WebDriverWait wait = new WebDriverWait(driver, 6);
wait.until(ExpectedConditions.elementToBeClickable(el));
return true;
}
catch (Exception e){
return false;
}
}
What is the equivalent solution using Javascript? I see several conditions in the documentation for the until module, but I don't see how to test if a button is clickable. Any help would be appreciated!
The accepted answer for this post describes a solution for Java. In another answer on that post a solution for Javascript is given. However I would like to wait until the element is not hidden anymore. I dont want to click the button while it is hidden, because that would invalidate my test.
P.s: I now test if a toast is visible and then wait for the toast to close before continuing my tests. However I would prefer a more general solution.