Selenium 3.0是否支持使用Action Class的moveHover Operations(moveToElement)?

时间:2016-12-10 12:07:58

标签: java selenium

我正在尝试在Java中执行mouseHover操作但是获得以下异常

org.openqa.selenium.UnsupportedCommandException: POST /session/10089ef9-f491-4b9c-a295-d9246dd39e02/moveto did not match a known command
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:48:19 -0700'
System info: host: 'SHI58495EU1003F', ip: '192.168.0.105', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_66'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
  • 手动步骤
  • 导航至网站" http://www.fatcow.com/"
  • 执行mouseHover on"创建网站"链路
  • 点击选项"原始FatCow"选项。

我是否已成功编写可执行代码或缺少任何内容? PFB COde

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.Test;

public class mousehover {

    WebDriver driver;

    @Test
    public void start()
    {
        System.setProperty("webdriver.gecko.driver", "C:\\Users\\rkumar\\Desktop\\geckodriver.exe");
        driver  = new FirefoxDriver();
        driver.navigate().to("http://www.fatcow.com/");
        Actions action = new Actions(driver);
        WebElement createAsite = driver.findElement(By.linkText("Create a Site"));
        WebElement original = driver.findElement(By.linkText("Original FatCow"));
action.moveToElement(createAsite).moveToElement(original).click().build().perform();        
    }
}

1 个答案:

答案 0 :(得分:0)

鼠标悬停操作可以使用Java脚本执行器(没有操作类)实现:

String javaScript = "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) driver).executeScript(javaScript, hoverElement);
    assertion