我正在尝试在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
我是否已成功编写可执行代码或缺少任何内容? 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();
}
}
答案 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