/**
  * Ensures that the provided node is visible and we can interact with it.
  *
  * @throws ExpectationException
  * @param NodeElement $node
  * @return void Throws an exception if it times out without the element being visible
  */
 protected function ensure_node_is_visible($node)
 {
     if (!$this->running_javascript()) {
         return;
     }
     // Exception if it timesout and the element is still there.
     $msg = 'The "' . $node->getXPath() . '" xpath node is not visible and it should be visible';
     $exception = new ExpectationException($msg, $this->getSession());
     // It will stop spinning once the isVisible() method returns true.
     $this->spin(function ($context, $args) {
         if ($args->isVisible()) {
             return true;
         }
         return false;
     }, $node, self::EXTENDED_TIMEOUT, $exception, true);
 }