我遇到了Actions act= new Actions(d1);
act.moveToElement(d1.findElement(By.xpath("path of the element")).build().perform();
类驱动程序的问题。我有这段代码
Selenium-Java 2.43.0
以前当我使用3.0.0-beta2
时,此命令运行正常。但我已升级到firefox driver
,通过gecko驱动程序开始访问<div class="addthis_responsive_sharing"> <!-- This line initiates the plugin to generate the rest of the code -->
<div id="share-this"> <!-- I want to hide this div only if the plugin is blocked or if it's elements aren't visible on the screen for some other reason -->
<div class="share-text">Share this!</div>
<span class="share-arrow right-arrow" style="font-size:24px;">⤹</span>
</div>
<!-- This is the parent div for the actual social buttons-->
<div id="atrsb" class="at-resp-share-element addthis_32x32_style at-mobile addthis-smartlayers addthis-animated at4-show">
<!-- Facebook - I pulled this from the live code just to display the FB icon -->
<span class="at-icon-wrapper" style="background-color: rgb(59, 89, 152);">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 32 32" title="Facebook" alt="Facebook" class="at-icon at-icon-facebook" style="fill: rgb(255, 255, 255);">
<g>
<path d="M22 5.16c-.406-.054-1.806-.16-3.43-.16-3.4 0-5.733 1.825-5.733 5.17v2.882H9v3.913h3.837V27h4.604V16.965h3.823l.587-3.913h-4.41v-2.5c0-1.123.347-1.903 2.198-1.903H22V5.16z" fill-rule="evenodd">
</path>
</g>
</svg>
</span> <!-- /.Facebook -->
</div> <!-- /.atrsb -->
</div> <!-- /.addthis_responsive_sharing>
。
在上面指定的命令中,我的测试失败了。我得到以下异常
org.openqa.selenium.UnsupportedCommandException:POST / session / 21dfc828-a382-4622-8c61-89bc48e29744 / moveto与a不匹配 已知命令(警告:服务器未提供任何堆栈跟踪 信息)命令持续时间或超时:4毫秒
请帮忙
答案 0 :(得分:5)
临时,可怕,令人沮丧的答案,直到他们解决这个问题,才能恢复到Selenium和Firefox的工作版本。使用Firefox 45.0.2的Selenium 2.53.0仍然有效: https://ftp.mozilla.org/pub/firefox/releases/45.0.2/
我很遗憾没有对最新的测试进行测试,但与此同时它根本没有运行任何Firefox测试。几个月没有针对Firefox运行 是不可接受的。
答案 1 :(得分:5)
这是版本问题。 Selenium 3还没有支持Actions类驱动程序。您必须下载到较低版本。版本2.53.1适用于我的Firefox
答案 2 :(得分:0)
下面适用于Firefox 52.3.0 ESR和Selenium 3.5.1
public void mouseRightClickAndSelectOption(By locator, By contextMenuOption){
clickElement(locator);
String script = "var evt = document.createEvent('MouseEvents');" + "evt.initMouseEvent('contextmenu',true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0,null);" + "arguments[0].dispatchEvent(evt);";
try {
((JavascriptExecutor) driver).executeScript(script, getElement(locator));
} catch (Exception ignored) {
}
clickElement(contextMenuOption);
}
public WebElement getElement(By locator) {
fluentWait(locator);
return driver.findElement(locator);
}