Firefox 12.0和Selenium 2:不支持本机事件

时间:2012-05-17 18:02:27

标签: firefox selenium automated-tests selenium-webdriver

使用webdriver运行Selenium 2.21.0版本时,在针对Firefox 12.0运行时出现以下错误:

org.openqa.selenium.InvalidElementStateException: Cannot perform native interaction: Could not load native events component.
Command duration or timeout: 20.08 seconds
Build info: version: '2.2.1', revision: '16551', time: '2012-04-11 21:42:35'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_26'
Driver info: driver.version: RemoteWebDriver
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:175)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:128)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:459)
    at org.openqa.selenium.remote.ExecuteMethod.execute(ExecuteMethod.java:47)
    at org.openqa.selenium.remote.RemoteMouse.mouseMove(RemoteMouse.java:89)
    at org.openqa.selenium.interactions.internal.MouseAction.moveToLocation(MouseAction.java:31)
    at org.openqa.selenium.interactions.ClickAndHoldAction.perform(ClickAndHoldAction.java:39)
    at org.openqa.selenium.interactions.CompositeAction.perform(CompositeAction.java:32)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:229)
    at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:121)
    at isishelper.ActionHelper.placement_placeSampleOnContainer(ActionHelper.groovy:195)
...

本案例中的代码如下:

List sourceSamples = sourceTable.findElements((By.className("x-grid-row")))
List poolTargets = driver.findElements(By.className("pool-box"))
target = poolTargets[0]    
def source = sourceSamples[0]
// Then drag and drop the sample to target
(new Actions(driver)).dragAndDrop(source, target).perform()

我认为这是缺少功能,因为Selenium 2.21是在Firefox 12.0之前发布的,而不是在我设置驱动程序时出错?

检查驱动程序属性:

driver.getCapabilities().asMap().each { 
             index, value -> println("$index : $value") 
}
browserName : firefox
nativeEvents : false
takesScreenshot : true
version : 12.0

但是在使用配置文件创建驱动程序时,我得到nativeEvents = true:

profile.setEnableNativeEvents(true); 
println profile.getProperties()
driver = new FirefoxDriver(profile)
[enableNativeEvents:true, 
class:class org.openqa.selenium.firefox.FirefoxProfile,
additionalPreferences:org.openqa.selenium.firefox.Preferences@82d37]

3 个答案:

答案 0 :(得分:4)

webdriver 2.21尚不支持绝对原生事件。根据{{​​3}},只有FF10和11目前正在实施此功能。

我不知道这是否与问题有关,但是在代码的最后一行不应该在调用perform()之前调用build()? (这必须用Java完成)

更多的堆栈跟踪可能会有所帮助。您在哪一行收到此错误?您是否尝试将本机事件明确设置为false?

答案 1 :(得分:2)

Selenium 2.29.0发布时支持FF18(适用于原生事件)。 以下是更新的链接:http://selenium.googlecode.com/git/rb/CHANGES

可能会更新到FF18,selenium-webdriver(2.29.0)可能会对您有所帮助。

答案 2 :(得分:1)

Selenium 2.22.0已经发布,更新日志表明他们现在支持Firefox 12中的本机事件。我已经测试了它,它看起来效果很好。