gpt4 book ai didi

java - Selenium 网络驱动程序 : List is not generic; it cannot be parameterized with arguments `` type

转载 作者:行者123 更新时间:2023-11-29 06:51:52 25 4
gpt4 key购买 nike

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

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

但在使用列表时遇到错误

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

最佳答案

这是您问题的答案:

错误说明了一切The type List is not generic; it cannot be parameterized with arguments <WebElement> type .这意味着当您配置​​ ListList<WebElement> linkElements ,你不小心从 java.awt.List 导入了它未定义的地方。因此错误。

下面的截图展示了这一切:

enter image description here

解决方案:

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

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]

如果这回答了您的问题,请告诉我。

关于java - Selenium 网络驱动程序 : List is not generic; it cannot be parameterized with arguments `<WebElement>` type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45402867/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com