0

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.

  • Use This : `public static void elementToBeClickable(WebDriver commonPage, By locator, int timeOut) { wait = new WebDriverWait(commonPage, timeOut); wait.until(ExpectedConditions.visibilityOfElementLocated(locator)); LOGGER.info("Element is visible now"); wait = new WebDriverWait(commonPage, timeOut); wait.until(ExpectedConditions.elementToBeClickable(locator)); Actions act = new Actions(commonPage); act.moveToElement(commonPage.findElement(locator)).build().perform(); LOGGER.info("Element can be clicked now"); }` – Kushal Bhalaik Jul 12 '18 at 07:31
  • @Kushal Thanks for your answer. This code in your answer looks like Java, while I am looking for a solution in Javascript. Do you know what the equivalent of your solution is in Javascript? – Erik van den Hoorn Jul 12 '18 at 08:03
  • 1
    I don't know abt JS but for protractor you can try : `var EC = protractor.ExpectedConditions; browser.wait(EC.elementToBeClickable (element.all(by.id('option'))), 20000);` – Kushal Bhalaik Jul 12 '18 at 08:08
  • @Kushal Thanks for pointing out Protractor. I was not aware yet of this test framework specially designed for AngularJS applications. I was writing my test scripts with just Selenium-Webdriver. – Erik van den Hoorn Jul 12 '18 at 08:37

0 Answers0