我现在正在自动化一个 Web 应用程序。我使用了一个列表数组来定位容器中的几个对象。我需要做的就是我必须将鼠标悬停在第一个元素上并单击它。但是鼠标悬停方法我已经写在另一个类中作为普通函数了。那么我可以使用列表数组的对象以任何方式传递给鼠标悬停方法吗?
查找容器中的元素。
By by = By.xpath("//ul[@id='sortable']");
List<WebElement> featureList= element.findElements(by.tagName("a"));
//Mouse-hover method
public static void moveMouseOver(WebDriver driver, By locator) {
WebElement element = waitForElementPresent(driver, locator);
(new Actions(driver)).moveToElement(element).build().perform();
}
Here can I change the 'By Locator' argument to replace with List array object ?
最佳答案
您可以尝试将 moveMouseOver 更改为类似的内容:
public static void moveMouseOver(WebDriver driver, WebElement... webElements){
if(null != webElements){
for(WebElement webEl : webElements){
// do something here
}
}
}
然后称它为
moveMouseOver(driver, ((WebElement[])featureList.toArray()))
请检查是否有语法错误,因为我只是在这里写的,并没有在 IDE 中检查过
关于java - 我们可以将 List<WebElement> 的对象作为参数传递给函数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29140177/