1

In one of my Selenium test cases, I have the problem that there are MouseOver effects that I don't want to have. This is what I do:

  1. Click on the "login" button (top-right of the page)
  2. Wait for page to load
  3. Click on the "buy" button in the search results (middle-right of the page).

The problem is, that there is a "shopping basket" link with a MouseOver effect right in the middle between "login" and "buy". So when I call Click() on the "login" button and afterwards on the "buy" button, I trigger the MouseOver, which opens a small preview of the shopping cart, which hides the "buy" button behind itself.

This goes for Firefox and MSIE. In Chrome, I don't have this kind of effect.

Any idea anyone?

Kim Homann
  • 3,042
  • 1
  • 17
  • 20
  • How is this different from what a human user would see? Are you sure the browser differences aren't just a bug in the site? – Andrew Regan Feb 09 '16 at 14:05
  • The human user would notice that the popup menu overlays the "buy" button and would move the mouse away so the popup disappears. And why is this not a problem in Chrome? I would like to find a way to position the virtual mouse pointer immediately over the target element instead of moving it there in a real-life-like slow movement. – Kim Homann Feb 10 '16 at 13:00
  • Firstly it's impossible to say why Chrome is different. Probably a site bug, but I can only guess as no link has been provided. I think the missing piece is that if the site requires the human to move his mouse, then you must tell Selenium to do likewise. – Andrew Regan Feb 10 '16 at 13:04
  • It's hard to do much when you haven't provided a link to the site or HTML or any code either. – JeffC Feb 10 '16 at 18:08

2 Answers2

0

As Andrew is right. If it is not happening manually then it should not happened here as well.

You can also try to click using JavascriptExecutor

WebElement element= driver.findElement(By.xpath("Your Xpath"));

JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", element);

Below is some example that how you can do it using C#

Execute JavaScript using Selenium WebDriver in C#

Hope it will help you :)

Community
  • 1
  • 1
Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
0

I still don't know the real solution, but here's the dirty workaround I'm using:

public static void Click(this IWebElement element, TestTarget target)
{
    if (target.IsInternetExplorer)
    {
        var actions = new Actions(target.Driver);
        actions.MoveToElement(element).Perform();
        Thread.Sleep(500); // wait for the mouseover popup to appear
        element.SendKeys(Keys.Escape); // to close the popup (if any)
        actions.MoveToElement(element).DoubleClick().Perform(); // simple click is sometimes not enough in IE
    }
    else
    {
        element.Click();
    }
}
Kim Homann
  • 3,042
  • 1
  • 17
  • 20