0

I wanted to mouse hover on a menu which has many sub menu. In the websites where I researched they suggest below actions to use. But actions hovers over other menu there by hiding the actual element that has to be hovered.

Actions action = new Actions(Driver);
Actions hoverclick = action.MoveToElement(HomePageMaps.MegaMenuDevelopAndGrowAsManager());
hoverclick.Build().Perform();

Please suggest a java script for mouse hovering that can be used in selenium C# [Visual Studio IDE].

As well I have tried the below java script for hovering but it doesn't hover instead it just brings the focus on the element.

IJavaScriptExecutor exe = (IJavaScriptExecutor)Driver;
exe.ExecuteScript("arguments[0].fireEvent('onmouseover');", xpath of the element to be hovered());
Weedoze
  • 13,683
  • 1
  • 33
  • 63
Tinkle
  • 3
  • 3

2 Answers2

0

You could try and make use of the move to element action, this will simulate the action.

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
var element = wait.Until(ExpectedConditions.ElementIsVisible(By.Id(elementId)));

Actions action  = new Actions(driver);
action.MoveToElement(element).Perform();
Thomas
  • 431
  • 5
  • 17
AliHesam
  • 61
  • 1
  • 3
  • Thanks for your reply on my query. I tried the above piece of code but its not working. As I mentioned if i use actions it hovers other web element and hides the element which has to be hovered. – Tinkle Jun 02 '17 at 06:54
-1

Try using JQuery,

IJavaScriptExecutor exe = (IJavaScriptExecutor)Driver;
exe.ExecuteScript($("Your Element Selector").hover(function(){$(this).css("background-color", "white"); },); 

Your Element Selector - Give your Web Element which is to be hovered.

Chandra Shekhar
  • 664
  • 2
  • 9
  • 24