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());
4
  • the following link will help you enter link description here Commented Jun 2, 2017 at 6:33
  • Do you have a URL where we can test on? Commented Jun 2, 2017 at 7:13
  • @Tinkle Can you consider to share the relevant HTML DOM along with your work? Thanks Commented Jun 2, 2017 at 8:32
  • No guys URL and DOM is confidential :( Commented Jun 6, 2017 at 12:47

2 Answers 2

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();
Sign up to request clarification or add additional context in comments.

1 Comment

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.
-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.

Comments

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.