0

I need to hover over an element and click a link on the overlay that comes on hovering a div element. I use mouseOver() function and it works fine when the browser is in view area. However, if I minimize the browser, the mouseover doesn't work and gives the following error.

"Element is not currently visible and so may not be interacted with (WARNING: The server did not provide any stacktrace information)". Can someone help me on this, Please?

I user behat\mink\selenium2driver

user2596377
  • 61
  • 1
  • 4

1 Answers1

0

The browser window needs to be in focus for Selenium to control it reliably. If you interact with the browser, it will result in flickering tests.

So the message you get: "Element is not currently visible and so may not be interacted with" is literally the problem: Selenium does not see the element because the browser window is not displayed.

What you can do to troubleshoot issues like this one is capture a screenshot on failure. Add the following to your FeatureContext.php file:

public function writeDebugInfoAfterFailedStep($event)
{
  if (4 === $event->getResult()) { // if step failled
    $driver = $this->getSession()->getDriver();
    $outputFile = 'behat_' . date("Y-m-d H:i:s");

    if (($driver instanceof Selenium2Driver)) {
        $outputFileImg = $outputFile . '.png';
        $this->saveScreenshot($outputFileImg, "screenshots/");
    }
    $content = $this->getSession()->getPage()->getContent();
    $outputFile = $outputFile . '.html';
    file_put_contents("screenshots/" . $outputFile, $content);
    return;
  }
}

You should then get a screenshot in the 'screenshots' directory (you need to create that directory, first).

Another situation when this issue occurs is when the selector matches several elements and tries to interact with the wrong one, one that is not visible. This can happen if the CSS of the page is invalid and several elements have the same id for example. Solution: improve your selector to be sure to get the proper element.

And if that doesn't help, here are the conditions that determine if Selenium webdriver sees an element or not: https://dvcs.w3.org/hg/webdriver/raw-file/tip/webdriver-spec.html#determining-if-an-element-is-displayed (Check not only the visibility of an element, but also the visibility of its parents).

user2707671
  • 1,694
  • 13
  • 12