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

后端 未结 2 1161
醉梦人生
醉梦人生 2021-01-26 00:20

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

public class frameswitch {

public static void main(String[] args) {

    System.setProperty(\"webdriver.ge         


        
相关标签:
2条回答
  • 2021-01-26 00:26

    Check your import you have imported List from

    java.awt.List
    

    instead of

    java.util.List
    
    0 讨论(0)
  • 2021-01-26 00:35

    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:

    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.

    0 讨论(0)
提交回复
热议问题