McCoy
McCoy

Reputation: 820

Selenium webdriver - mouseover and dropdown menu - mouse inside/outside the browser issue

Specs: Windows 7; selenium 2.39.0; Java - Eclipse


I'm currently using Selenium to test a webApp through three different browsers (Chrome, IE9 and Firefox). The webApp has a menu bar, and there are located dropdown menus (classic). I need to set the mouse over one item of that menu bar and wait for a dropdown menu to appear, then I need to click in one of the dropdown menu items.

My code:

        WebElement div_menu = driver.findElement(By.xpath("//div[text() = 'Trigger of the dropdown menu']"));

        WebDriverWait wait = new WebDriverWait(driver, 300);
        Actions builder = new Actions(driver);    
        builder.moveToElement(div_menu).build().perform();

        WebElement item_to_click = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("Link_inside_the_dropdown_menu")));

        item_to_click.click();

The funny stuff occurs when I start the test. (FYI Browsers come up one by one, that is to say, all tests are performed for one browser before going on with other one, not threaded.)

If the mouse pointer is over the browser (because they are started not full maximized) at the time the tests are performed, then here are the results:

Now, let's see what happens when I left the mouse outside the browser window.

As you can see, the code is the same for the three of the browsers. The funny variable here is the mouse_in_browser and mouse_out_browser. I can't imagine what the problem could be. If you need any extra info, please don't hesitate.

Thank you very much in advance!

Upvotes: 0

Views: 5217

Answers (1)

McCoy
McCoy

Reputation: 820

I managed to get Firefox to work no matters where the physical mouse is. I initialized it this way:

            //Firefox initialization
              FirefoxProfile profile = new FirefoxProfile();
            //explicitly enable native events(this is mandatory on Linux system, since they
            //are not enabled by default
              profile.setEnableNativeEvents(true);
              WebDriver driver = new FirefoxDriver(profile);

This did the trick for me regarding Firefox. Not yet the others two.

Source: Selenium WebDriver mouse actions moveToElement doesn't raise mouseout event on Firefox Linux

Upvotes: 1

Related Questions