1

I have a selenium UI test written in Java that hovers over an element using Actions.

    WebElement element = driver.findElement(By.cssSelector("path to element"));
    Actions hover = new Actions(driver);
    hover.moveToElement(element).perform();

This works running it through commandline, but fails when it's runs on a Jenkins windows node. I have read that instead of using Actions, to use JavascriptExecutor. I have been researching how to do that and came up with

    String strJavaScript = "var evObj = document.createEvent('MouseEvents');"
            + "evObj.initMouseEvent(\"mouseover\", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);"
            + "arguments[0].dispatchEvent(evObj);";
    JavascriptExecutor js =  (JavascriptExecutor) driver;
    js.executeScript(strJavaScript, HoverElement);

But this doesn't seem to work either. What am I missing?

1
  • Add windows size to your driver setup. For chrome chromeOptions.addArguments("--window-size=1920,1080"); Commented Apr 21, 2023 at 8:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.