是否有任何替代方法可以使用java 1.8 gecko驱动程序0.19和firefox 56将鼠标悬停在selenium框中

时间:2018-02-20 09:36:53

标签: java selenium firefox selenium-webdriver selenium-grid

使用操作会将异常视为 unsupportedCommandException。

试图做这样的事情:

Actions action = new Actions(driver);
action.moveToElement(element).build().perform();
driver.findElement(By.linkText("All Actions")).click();

Element是我试图悬停的webElement

也试过这个:

((JavascriptExecutor) driver).executeScript("arguments[0].focus();",element);
((JavascriptExecutor) driver).executeScript("arguments[0].click();", element);

但没有运气。

我正在使用 seleniumbox 并使用最新版本的 selenium 3.9.1

3 个答案:

答案 0 :(得分:0)

根据您的问题,首先只需鼠标悬停元素,您必须等待元素可见。使用 Selenium-Java Client v3.9.1 ChromeDriver v2.35 Chrome v 63.0 ,这段代码在我的最终完美无缺:

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("xpath_of_element")));
Actions action = new Actions(driver);
action.moveToElement(element).perform();

更新

根据你的问题:

  • 您正在使用 GeckoDriver v0.19 Firefox 56.x

根据跟踪日志:

  • 您正在使用 Selenium Client v3.4.0

3.4.0

Geckodriver v0.19.0 (2017-09-16)的发行说明明确提到:

Note that with geckodriver 0.19.0 the following versions are recommended: - Firefox 55.0 (and greater) - Selenium 3.5 (and greater)

因此您会看到错误:

Caused by: org.openqa.selenium.UnsupportedCommandException: mouseMoveTo Build info: version: '3.4.0', revision: 'unknown', time: 'unknown

答案 1 :(得分:0)

Action不起作用。可能的解决方案是将 Firefox GeckoDriver 的版本更改为更低版本(稳定版本)。

IEDriver的示例:

selenium-standalone install --version=2.47.0 --drivers.ie.version=2.53.1

selenium-standalone start --version=2.47.0 --drivers.ie.version=2.53.1

答案 2 :(得分:0)

尝试更改这样的代码会有所帮助:

Actions action = new Actions(driver);
action.moveToElement(element).moveToElement( driver.findElement(By.linkText("All Actions"))).click().build().perform();