Selenium webdriver : List is not generic; it cannot be parameterized with arguments `<WebElement>` type

10,221

Here is the Answer to your Question:

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:

enter image description here

Solution:

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);
    }

}

The output on the console is:

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.

Share:
10,221
Gaurav Singh
Author by

Gaurav Singh

Updated on December 03, 2022

Comments

  • Gaurav Singh
    Gaurav Singh over 1 year

    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

    The type List is not generic; it cannot be parameterized with arguments <WebElement> type

    • Dioxin
      Dioxin almost 7 years
      Did you import java.util.List? You may have accidentally imported java.awt.List, check your imports.
  • Gaurav Singh
    Gaurav Singh over 6 years
    thanks and above code helps and now i can easily calculate links on any webpage.