我正在开发 Liferay 6.2 项目。在 Liferay 中,他们使用 Vaadin。当我点击一个按钮时,它会打开一个不同的 iframe。我可以编写所有功能的代码。现在我想使用 WebDriver 将光标移动到 iframe 元素。因为当我将鼠标移至 iframe 复选框后,我的自动化脚本就可以运行。我想自动化一个脚本来将鼠标指针移动到元素。
我已经尝试过下面的代码,但它不起作用。
1)使用Action moveToElement
:
driver.findElement(By.xpath("element1")).click();
new Actions(driver).moveToElement(driver.findElement(By.xpath("element2"))).click().perform();
2)使用mouseMove
WebElement element = driver.findElement(By.xpath("element xpath"));
Locatable hoverItem = (Locatable) element;
Mouse mouse = ((HasInputDevice) driver).getMouse();
mouse.mouseMove(hoverItem.getCoordinates());
错误:在((HasInputDevice)驱动程序)中出现错误。
HasInputDevice 无法解析为类型
3)
Locatable hoverItem = (Locatable) driver.findElement(By.xpath("element xpath"));
int y = hoverItem.getCoordinates().getLocationOnScreen().getY();
((JavascriptExecutor)driver).executeScript("window.scrollBy(0,"+y+");");
错误: getLocationOnScreen() 中出现错误
坐标类型的 getLocationOnScreen() 方法未定义
4)
Point coordinates = driver.findElement(By.xpath("element xpath")).getLocation();
Robot robot = new Robot();
WebElement markNews = driver.findElement(By.xpath("element xpath"));
markNews.click();
robot.mouseMove(coordinates.x,coordinates.y+80);
这是行不通的。
我只想将光标移动到 iframe 定位器。
您可以使用以下方式直接选择 iframe:
driver.switchTo().frame(driver.findElement(By.id("frameId")));
现在,通过使用 selenium Web 驱动程序,您可以在此 iframe 中执行任何操作。
要返回主窗口,您只需:
driver.switchTo().defaultContent();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)