java - 我们可以将 List<WebElement> 的对象作为参数传递给函数吗?

标签 java jakarta-ee selenium selenium-webdriver

我现在正在自动化一个 Web 应用程序。我使用了一个列表数组来定位容器中的几个对象。我需要做的就是我必须将鼠标悬停在第一个元素上并单击它。但是鼠标悬停方法我已经写在另一个类中作为普通函数了。那么我可以使用列表数组的对象以任何方式传递给鼠标悬停方法吗?

SCREEN SHOT

查找容器中的元素。

 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/

相关文章:

apache - 在 Apache Tomcat 中运行 Servlet

python - selenium.common.exceptions.WebDriverException : Message: unknown error: Chrome failed to start: crashed with ChromeDriver and Selenium in Python

java - 在 Eclipse 中将 Java Enums 和 ArrayList 与 JAX-WS 结合使用

java - Apache Camel - 基于正文聚合消息

java - assertEquals,什么是实际的,什么是预期的?

java - 我可以使用 spring security 将完整的用户信息存储在 cookie 中吗?

java - GlassFish 如何成为 OSGi 容器?

python - 如何使用 selenium (Python) 定位 Instagram 关注按钮

testing - 如何处理功能测试中的依赖关系?

java - Jersey 客户端,当使用 Maven 执行应用程序时使用 JAXBContext,但不使用 java -jar