Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save delphian/6255239 to your computer and use it in GitHub Desktop.
Save delphian/6255239 to your computer and use it in GitHub Desktop.
A replacement for mink's NodeElement mouseOver method. Occationally the mouseOver method will not cause the desired effect (such as when custom javascript is watching for a change of rate in the mouse location before popping up a menu item).
/**
* More reliable way to hover over an element. Talk to selenium directly.
*
* @param string $selector
* CSS selector.
* @param int $sleep
* Number of seconds to sleep after hover is initiated. Allows some
* slower third party javascript to do its thing before moving on
* with more test steps.
*
* @see https://code.google.com/p/selenium/wiki/JsonWireProtocol
* @see https://github.com/facebook/php-webdriver
*/
protected function mouseOver($selector, $sleep = 0)
{
// This returns a WebDriver\Session instance.
$driverSession = $this->getSession()->getDriver()->getWebDriverSession();
$element = $driverSession->element('css selector', $selector);
$driverSession->moveto(array('element' => $element->getID()));
// Allow any slow javascript to do its thing.
if ($sleep) {
sleep($sleep);
}
}
@delphian
Copy link
Author

Specifically NodeElement::mouseOver() would not cause the desired effect when working with the jQuery plugin hoverIntent (https://github.com/briancherne/jquery-hoverIntent)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment