Search code examples
seleniumtestingcucumberbehatgherkin

Behat / Selenium - Element is visible but not visible for testing framework


I am not sure is it Behat or Selenium issue, but on Google's account page where user can manage and remove connected to account apps - I can not actually delete one with Behat, because it thinks that elements in dialog confirming removing are invisible.

The page is here: https://security.google.com/settings/security/permissions

If you have any connected to your google account app (like Quora or anything else) click Remove you will see confirmation dialog, it has button OK in it, I can select this element with Behat, but $el->isVisible() returns false.

Do not know what to do. Any ideas?

enter image description here


Solution

  • Can not say why it is invisible but you can just go ahead and click it with JavaScript, like this:

        $cssSelector = "div[role='dialog'] div[role='button'][autofocus] SPAN";
    
        $js  = 'var event = document.createEvent("HTMLEvents");';
        $js .= 'var element = document.querySelectorAll("'.$cssSelector.'")[0];';
        $js .= 'event.initEvent("click", true, true);';
        $js .= 'event.eventName = "click";';
        $js .= 'element.dispatchEvent(event);';
    
        $this->getSession()->executeScript($js);