我使用Fitnesse来定义一些selenium测试。我们让它们都在CHROME下运行,但在FIREFOX下出现了一些例外。为了运行测试,我使用的是外部铬webdriver。也就是说,我使用selenium-server 2.7.0并以以下方式启动它:
D:\projects\dev\jdk\1.6\bin\java -jar ./selenium-server-standalone-2.7.0.jar - Dwebdriver.chrome.driver=c:\chromedriver\chromedriver.exe -Dfile.encoding=UTF8
__EXCEPTION__:org.openqa.selenium.InvalidElementStateException: Cannot perform native interaction: Could not load native events component.; duration or timeout: 2.05 seconds
Build info: version: '2.7.0', revision: '13926', time: '2011-09-23 13:24:59'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_16'
Driver info: driver.version: RemoteWebDriver; duration or timeout: 2.06 seconds
Build info: version: '2.7.0', revision: '13926', time: '2011-09-23 15:09:51'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_16'
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:147)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:113)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:397)
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.MoveMouseAction.perform(MoveMouseAction.java:37)
at org.openqa.selenium.interactions.CompositeAction.perform(CompositeAction.java:32)
at com.bmw.next.selenium2.util.MouseUtil.moveToElement(MouseUtil.java:22)
....也就是说,抛出了一个异常InvalidElementStateException,我不明白是什么错了。火狐和Chrome的代码是一样的。有人经历过这种行为吗?
任何提示都将不胜感激。
提前谢谢。
发布于 2012-01-22 02:54:00
我猜你的元素不存在。使用Firefox驱动程序的Click()方法不像Selenium中的ClickAndWait那样工作。在单击某物之前,必须显式地执行隐式等待。我的猜测是,您连续单击了2次,第二次单击失败了,因为该元素还不存在,因为第一次单击提交了表单或其他内容。
在失败的代码行之前调用此方法。您需要找到这个C#代码的Java实现,但我认为它可能解决了您的问题。
public static IWebElement FindElement(this IWebDriver driver, By by, int timeoutInSeconds)
{
if (timeoutInSeconds > 0)
{
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds));
return wait.Until(drv => drv.FindElement(by));
}
return driver.FindElement(by);
}发布于 2012-06-17 21:05:49
你也可以遵循这个程序。
首先,将web元素复制到web元素类型的变量中:
webelement elem=driver.findElement(By.id("elementid"));现在采取行动
elem.click();当DOM元素发生变化时,id将与堆栈不一样,因此当在元素标识后进行单击操作时,它将再次检查相同的元素。
此过程可用于可能的异常,如staleelementexception或elementnotfound。
https://sqa.stackexchange.com/questions/1894
复制相似问题