Skip to content

Can't get mouseOver() to trigger :hover event #125

Closed

Description

@J7mbo

I am working with a legacy codebase and I'm having trouble getting mouseOver() to trigger a :hover css event. This code is used all over the place and currently my only workaround is having to run executeScript() and manually remove the .dropout and .dropout-trigger classes. Please help me figure out what I can do to solve this.

I've set up a barebones repository containing a single, basic, HTML file, the CSS I have managed to isolate, and a test.

I have included the vendor/ folder simply so you can get up to speed straight away. I run selenium-server-standalone and phpunit:

java -jar bin/selenium-server-standalone-2.40.0.jar -Dwebdriver.chrome.driver=bin/chromedriver-2.9

bin/phpunit.phar --colors --bootstrap bootstrap.php --filter testMouseOverFail src/

My test is as follows:

public function testMouseOverFail()
{
    $driver = new \Behat\Mink\Driver\Selenium2Driver("chrome", array(), "http://localhost:4444/wd/hub");
    $session = new \Behat\Mink\Session($driver);
    $session->start();

    // I placed this all in /var/www/mouseoverfail
    $session->visit("http://localhost/mouseoverfail");

    $page = $session->getPage();

    $services = $page->find('xpath', '//*[@id="nav_services"]');

    var_dump("Services visibility: " . $services->isVisible());

    $services->mouseOver(); // Nothing is hovered over :(

    sleep(5);

    $session->stop();
}

Like I said, I'm working with legacy code here and the css is all over the place. It's highly likely that it's our css / html that is the issue and not mink / selenium2driver, but I would just like to find out how I can solve this, as my manual executeScript() haxx are just terrible.

Activity

  1. aik099 commented on Apr 9, 2014

    @aik099
    Member

    Regardless to your case it's obvious why the ":hover" doesn't work: the "mouseover" event has been triggered by the Syn() library while the mouse cursor isn't even moved.

    We can do a native "moveTo" call of WebDriver in hopes that it will trigger the "mouseover" JS event. Or we can trigger "mouseover" JS event ourselves after the "moveTo" call has finished.

    Can you please try that out and send a PR+tests for that?

  2. J7mbo commented on Apr 9, 2014

    @J7mbo
    Author

    Following your advice I have gotten it working by retrieving the element using WebDriver and calling moveto() within mouseOver() before the syn event is executed.

    Could you suggest the best way to submit tests alongside this PR? I saw mink has some tests in there but this is a separate repo... Do I need to submit this and a test fixture in the main mink repo?

  3. aik099 commented on Apr 9, 2014

    @aik099
    Member

    There should 2 PR in total:

    1. actual code change in driver repo
    2. tests in the JavaScriptDriverTest class in mink repo

    Problem is, that you won't see the added tests running in the driver tests on Travis, until that mink repo PR is merged.

    Also since you're adding tests to common test class, then please run these tests on all existing drivers and make sure that they also pass.

    To make both PR's associated I usually mention driver repo issue/pr for which the tests are for in the mink pr.

    And also add a test (this one will be Selenium2 specific in driver repo), that mouseover event isn't fired more than once.

  4. J7mbo commented on Apr 9, 2014

    @J7mbo
    Author

    I've added the test that needs to pass and a fixture for it in a fork.

    I'm not sure about the other existing drivers though, I may need a little help with that :-) (I've only used Selenium2Driver).

    Here's the code change to the driver.

    How are these looking?

  5. aik099 commented on Apr 9, 2014

    @aik099
    Member

    You can send a PR in any case. Even if it breaks something then we can discuss that right on PR page.

  6. J7mbo commented on Apr 10, 2014

    @J7mbo
    Author

    A problem I have found is that, in order for moveto to work, and for the mouseOver() call to work with :hover, the code looks as follows:

    $this->wdSession->moveto(array(
        'element' => $element->getID()
     ));
    

    This requires that the element in question has an id attribute - which not all of them do. Is there any way around this? I have also seen xOffset as an option but this does not seem feasible. Can we pass an xpath instead of the id?

  7. aik099 commented on Apr 10, 2014

    @aik099
    Member

    Are you sure that getID method is returning the found DOM element's ID (from HTML) and not WebDriver/Selenium's internal identificator?

  8. stof commented on Apr 10, 2014

    @stof
    Member

    it is indeed a webdriver identifier

  9. J7mbo commented on Apr 10, 2014

    @J7mbo
    Author

    My bad, I'm still testing the code change myself before I submit a PR.

  10. aik099 commented on Apr 10, 2014

    @aik099
    Member

    If I have enough time this week, then I plan to submit massive PR in #126 issue, that will fix all mouse-related problems once and for all. To make this happen I'll collect all mouse-related PRs and incorporate them into my single PR.

    I'm warning you ahead, so you won't be surprised when PR gets closed instead of merged.

  11. J7mbo commented on Apr 10, 2014

    @J7mbo
    Author

    No that's great, I just want the issue fixed for when I do a composer update.

    I'm looking forward to seeing it if you have chance to get it done this weekend :-)

  12. aik099 commented on Apr 10, 2014

    @aik099
    Member

    I bet that both SeleniumRC and WebDriver will work, but I'm not sure about Sahi or PhantomJS.

  13. kenden commented on Apr 10, 2014

    @kenden

    Note if you don't want to wait for a composer update, you can add a method to your class:
    https://gist.github.com/delphian/6255239

  14. J7mbo commented on Apr 14, 2014

    @J7mbo
    Author

    @aik099 Any updates on this - weekend's gone, just thought I'd ask :P

  15. aik099 commented on Apr 14, 2014

    @aik099
    Member

    Sorry, this was already merged for click/doubleclick/rightclick/mouseover methods (see #126 task).

  16. aik099 commented on Apr 14, 2014

    @aik099
    Member

    I'll close this task since functionality is already merged in the #126. Feel free to reopen if needed.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions