How to do mouse hover using Selenium WebDriver in Firefox 19?

后端 未结 6 710
梦谈多话
梦谈多话 2020-12-14 10:14

I have used selenium 2.31.

I have used Actions class for mouse movement. Using this I moved the mouse over a menu and its submenu appeared only for a fraction of se

6条回答
  •  孤街浪徒
    2020-12-14 10:23

    Another way to go about this is to use Selenium's JavaScript Executor to force the style of the element to be displayed.

    An Example of this would be along this lines in C#

    //Use the Browser to change the display of the element to be shown
     (IJavaScriptExecutor)driver).ExecuteScript("document.getElementById('myId').stlye.display="block");
    
    //navigate to your link that is now viewable 
    driver.FindElement(By.Xpath('//LinkPath')).Click(); 
    

    From there, you can find the XPath to your element and use selenium to click on the element. You can cascade this to find children of your main element as well

    //(IJavaScriptExecutor)ffbrowser).ExecuteScript("document.getElementById('myId').children[1].children[1].style.display='block'");
    

    Note that this is only possible if you have a hover element that changes the display style when hovered over.

提交回复
热议问题