Is there a proved mouseOver workaround for FirefoxDriver in Selenium2?

后端 未结 3 789
夕颜
夕颜 2020-12-01 08:33

I\'m using Selenium Java 2.0b3. I have this code:

...
WebDriver driver = new InternetExplorerDriver();
Selenium seleniumDriver = new WebDriv         


        
相关标签:
3条回答
  • 2020-12-01 08:51

    I use this code to get a mouseover event for a specific webelement. It does not need native events.

    protected void mouseOver(WebElement element) {
        String code = "var fireOnThis = arguments[0];"
                    + "var evObj = document.createEvent('MouseEvents');"
                    + "evObj.initEvent( 'mouseover', true, true );"
                    + "fireOnThis.dispatchEvent(evObj);";
        ((JavascriptExecutor) driver).executeScript(code, element);
    }
    
    0 讨论(0)
  • 2020-12-01 08:56

    I would suggest trying the Advanced User Actions API that was added in the 2.0rc1 release yesterday, as it looks like you're using the Selenium 1 API still (going through WebDriverBackedSelenium), and I'm not sure how much Firefox 4 support that provides. I'm not using Java for my Selenium tests, but it looks to me like what you would want to do is something like this:

       Actions builder = new Actions(driver); // Or maybe seleniumDriver? Not sure which one to use
    
       Actions hoverOverRegistrar = builder.moveToElement(menuRegistrar);
    
       hoverOverRegistrar.perform();
    
    0 讨论(0)
  • 2020-12-01 09:04
    Actions action = new Actions(driver);
    action.moveToElement(element).build().perform();
    action.moveByOffset(1, 1).build().perform();
    
    0 讨论(0)
提交回复
热议问题