iframe中的selenium webdriver元素是可点击的,但moveToElement导致MoveTargetOutOfBoundsError [英] selenium webdriver element inside iframe is clickable but moveToElement results in MoveTargetOutOfBoundsError

查看:3082
本文介绍了iframe中的selenium webdriver元素是可点击的,但moveToElement导致MoveTargetOutOfBoundsError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iframe页面。 iframe内部是一张桌子。当用户将鼠标移动到该表格上时,会出现一些元素。我想点击其中一个元素。



我认为我的第一步应该是选择iframe,然后moveToElement(table)。但是这会导致MoveTargetOutOfBoundsError。



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



我怎么才能做到我想要的(选择iframe,悬停在桌子上,等待按钮出现,点击其中一个按钮)?

 构建信息:版本:'2.28.0',修订:'18309',时间:'2012-12-11 15:53:30 '
系统信息:os.name:'Windows 7',os.arch:'amd64',os.version:'6.1',java.version:'1.6.0_37'

$ b $ p

















$ p $ driver.switchTo()defaultContent();
driver.switchTo()。frame(frameId);
WebElement e = driver.findElement(By.id(foo));
e.click();

以下是抱怨表格位置的java代码:

  driver.switchTo()。defaultContent(); 
driver.switchTo()。frame(frameId);
WebElement e = driver.findElement(By.id(foo));
动作构建器=新动作(驱动程序);
builder.moveToElement(e).build()。perform(); //错误发生在moveToElement()中


解决方案

必须滚动到视图中:

  if(element instanceof Locatable){
Locatable remoteElement =(Locatable)inputElement;
remoteElement.getLocationOnScreenOnceScrolledIntoView();

$ / code>

如果您想要悬停在某个元素上,则必须将上面的a bit:

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


I have a page with an iframe. Inside the iframe is a table. When the user moves the mouse over this table, some elements appear. I'd like to click one of those elements.

I think some of my first steps should be to select the iframe, and then moveToElement(table). But this results in a MoveTargetOutOfBoundsError.

The strange thing is that I'm able to select the iframe and click on the table. The click doesn't complain about the element's x,y coordinates but moveToElement complains. Why? (Unfortunately clicking on the table performs an action which causes those buttons I want to disappear so this is not an option.)

And how can I accomplish what I want (select iframe, hover over table, wait for buttons to appear, click one of the buttons)?

version info:

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'

Here's the java code that succeeds in clicking the table:

driver.switchTo().defaultContent();
driver.switchTo().frame("frameId");
WebElement e = driver.findElement(By.id("foo"));
e.click();

Here's the java code that complains about the location of the table:

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()

解决方案

I think you have to scroll into view:

if (element instanceof Locatable) {
    Locatable remoteElement = (Locatable) inputElement;          
    remoteElement.getLocationOnScreenOnceScrolledIntoView();
}

If you want to hover on an element, you have to extend the above a bit:

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

这篇关于iframe中的selenium webdriver元素是可点击的,但moveToElement导致MoveTargetOutOfBoundsError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆