Selenium webdriver:列表不是通用的;不能使用参数`< WebElement>`类型进行参数化 [英] Selenium webdriver : List is not generic; it cannot be parameterized with arguments `<WebElement>` type

查看:208
本文介绍了Selenium webdriver:列表不是通用的;不能使用参数`< WebElement>`类型进行参数化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将链接存储在列表中,请遵循以下代码

I was trying to store link in List, follow below code

public class frameswitch {

public static void main(String[] args) {

    System.setProperty("webdriver.gecko.driver","C:\\geckodriver\\geckodriver.exe");  
    WebDriver driver=new FirefoxDriver();
    String baseUrl="https://www.udacity.com/";
    driver.get(baseUrl);
    String Title="Udacity - Free Online Courses and Nanodegree Programs";
    List<WebElement> linkElements = driver.findElements(By.tagName("a"));
    }
}

但在使用列表时遇到错误

but facing error while using list

列表类型不是通用的;不能使用参数<WebElement> type

推荐答案

以下是您的问题的答案:

Here is the Answer to your Question:

该错误说明了所有The type List is not generic; it cannot be parameterized with arguments <WebElement> type.这意味着,当您像在List<WebElement> linkElements中配置List时,意外地是从未定义它的java.awt.List导入了它.因此是错误.

The error says it all The type List is not generic; it cannot be parameterized with arguments <WebElement> type. It means when you configured the List as in List<WebElement> linkElements, accidentally you have imported it from java.awt.List where it is not defined. Hence the error.

以下屏幕截图显示了所有内容:

The following screenshot shows it all:

作为一种解决方案,我使用了自己的代码导入了java.util.List而不是java.awt.List,并且您的代码块也可以正常工作:

As a solution, I have used your own code importing java.util.List instead of java.awt.List and your code block works just fine:

package demo;

import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Q45402867_tagname_a {

    public static void main(String[] args) {
        System.setProperty("webdriver.gecko.driver","C:\\Utility\\BrowserDrivers\\geckodriver.exe");  
        WebDriver driver=new FirefoxDriver();
        String baseUrl="https://www.udacity.com/";
        driver.get(baseUrl);
        String Title="Udacity - Free Online Courses and Nanodegree Programs";
        List<WebElement> linkElements = driver.findElements(By.tagName("a"));
        System.out.println(linkElements.size());
        for (WebElement ele:linkElements)
        System.out.println(ele);
    }

}

控制台上的输出为:

86
[[FirefoxDriver: firefox on ANY (ef81931f-9530-4998-8405-6581ab51c86e)] -> tag name: a]
...  84 more ...
[[FirefoxDriver: firefox on ANY (ef81931f-9530-4998-8405-6581ab51c86e)] -> tag name: a]

让我知道这是否回答了您的问题.

Let me know if this Answers your Question.

这篇关于Selenium webdriver:列表不是通用的;不能使用参数`&lt; WebElement&gt;`类型进行参数化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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