package at.porscheinformatik.seleniumcomponents;

import org.openqa.selenium.WebElement;

/**
 * A {@link SeleniumComponent} that is clickable.
 *
 * @author ham
 */
public interface ClickableSeleniumComponent extends VisibleSeleniumComponent
{

    /**
     * Returns true if the component is clickable. Waits {@link SeleniumGlobals#getShortTimeoutInSeconds()} seconds for
     * the component to become available.
     *
     * @return true if clickable
     */
    default boolean isClickable()
    {
        try
        {
            return SeleniumUtils.retryOnStale(() -> {
                WebElement element = element();

                return element.isDisplayed() && element.isEnabled();
            });
        }
        catch (Exception e)
        {
            return false;
        }
    }

    /**
     * Waits {@link SeleniumGlobals#getShortTimeoutInSeconds()} seconds for the component to become clickable and clicks
     * it.
     */
    default void click()
    {
        LOG.interaction("Clicking on %s", describe());

        SeleniumAsserts.assertIsClickable(SeleniumGlobals.getShortTimeoutInSeconds(), this);
        SeleniumUtils.retryOnStale(() -> element().click());
    }

}

@@ -43,16 +43,56 @@
 nents;%0A%0A
+import static org.hamcrest.Matchers.*;%0A%0A
 import o
@@ -1107,128 +1107,199 @@
 sert
-IsClickable(SeleniumGlobals.getShortTimeoutInSeconds(), this);%0A        SeleniumUtils.retryOnStale(() -%3E element().click(
+ThatSoon(() -%3E %7B%0A            if (this.isClickable())%0A            %7B%0A                element().click();%0A%0A                return true;%0A            %7D%0A%0A            return false;%0A        %7D, is(true
 ));%0A

Make ClickableSeleniumComponent more stable