iframe中的selenium webdriver元素是可单击的,但moveToElement会导致MoveTargetAutoFBoundsError

iframe中的selenium webdriver元素是可单击的,但moveToElement会导致MoveTargetAutoFBoundsError,iframe,selenium,hover,webdriver,Iframe,Selenium,Hover,Webdriver,我有一个带有iframe的页面。iframe内部是一个表。当用户将鼠标移到此表上时,会出现一些元素。我想单击其中一个元素 我认为我的第一步应该是选择iframe,然后移动到lementtable。但这会导致MoveTargetAutofBoundsError 奇怪的是,我能够选择iframe并单击表。单击不会抱怨元素的x、y坐标,但会抱怨moveToElement。为什么?不幸的是,点击表格会导致我想要的按钮消失,所以这不是一个选项 我怎样才能完成我想要的呢?选择iframe,将鼠标悬停在表上,

我有一个带有iframe的页面。iframe内部是一个表。当用户将鼠标移到此表上时,会出现一些元素。我想单击其中一个元素

我认为我的第一步应该是选择iframe,然后移动到lementtable。但这会导致MoveTargetAutofBoundsError

奇怪的是,我能够选择iframe并单击表。单击不会抱怨元素的x、y坐标,但会抱怨moveToElement。为什么?不幸的是,点击表格会导致我想要的按钮消失,所以这不是一个选项

我怎样才能完成我想要的呢?选择iframe,将鼠标悬停在表上,等待按钮出现,然后单击其中一个按钮

版本信息:

Build info: version: '2.28.0', revision: '18309', time: '2012-12-11 15:53:30'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_37'
下面是成功单击表的java代码:

driver.switchTo().defaultContent();
driver.switchTo().frame("frameId");
WebElement e = driver.findElement(By.id("foo"));
e.click();
driver.switchTo().defaultContent();
driver.switchTo().frame("frameId");
WebElement e = driver.findElement(By.id("foo"));
Actions builder = new Actions(driver);
builder.moveToElement(e).build().perform(); // error happens in moveToElement()
下面是抱怨表位置的java代码:

driver.switchTo().defaultContent();
driver.switchTo().frame("frameId");
WebElement e = driver.findElement(By.id("foo"));
e.click();
driver.switchTo().defaultContent();
driver.switchTo().frame("frameId");
WebElement e = driver.findElement(By.id("foo"));
Actions builder = new Actions(driver);
builder.moveToElement(e).build().perform(); // error happens in moveToElement()

我认为您必须滚动到视图:

if (element instanceof Locatable) {
    Locatable remoteElement = (Locatable) inputElement;          
    remoteElement.getLocationOnScreenOnceScrolledIntoView();
}
如果要将鼠标悬停在某个元素上,则必须稍微扩展上面的选项:

if (element instanceof Locatable) {
    Locatable hoverItem = (Locatable) element;
    hoverItem.getLocationOnScreenOnceScrolledIntoView();
    Mouse mouse = ((HasInputDevices) webDriver).getMouse(); 
    mouse.mouseMove(hoverItem.getCoordinates());
}

你能发布你的代码吗?很有趣。。。它是可定位的。该位置为33314,与它投诉的位置1077127不同。但是,如果我在GetLocationScreenoneCrolledinToView之后创建一个Actions对象,并要求Actions对象移动到elemente.build.perform;它仍然抱怨大约1077127人。我应该怎么做?您需要使用moveToElement吗?GetLocationScreeNonSecrolledToView通常应使元素上的显示居中。你在测试什么浏览器?我在Firefox 17.0.1中进行测试,但我希望最终能得到对任何浏览器都有效的东西。GetLocationScreeNonSecrolledToView会一直滚动到桌子位于顶部+中间,但它没有导致按钮出现的悬停效果,或者至少在我观看时感觉不到。除了moveToElement之外,还有什么我可以用来做悬停的吗?等一下,现在在稍后的尝试中moveToElement没有抱怨。最新结果:GetLocationsScreenOnCercrolledToView,后面是一个以moveToElementtable开头的操作链,使按钮短暂显示,就像用户在表上悬停一样。但是,任何试图将moveToElementbutton或clickbutton甚至dragAndDroptable按钮放在moveToElementtable之后的操作链中的行为都会导致MoveTargetAutofBoundsError。。。