gpt4 book ai didi

java - Selenium 网络驱动程序 : Iterator cannot be resolved to a type

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:17:25 26 4
gpt4 key购买 nike

我的问题简述:

现在通过我的 selenium 网络驱动程序,我正在测试列表框中的元素列表,在使用以下代码时出现错误

测试配置:

  • 火狐浏览器
  • eclipse 靛蓝
  • Selenium 网络驱动程序 2

我测试的场景:

  1. 打开网站
  2. 选择并显示列表框项目
  3. 写到控制台

我的错误:

java.lang.Error: Unresolved compilation problems: The type List is not generic; it cannot be parameterized with arguments Iterator cannot be resolved to a type

我的代码:

package com.example.tests;

import java.util.Iterator;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.WebElement;
import org.openqa.jetty.html.List;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import com.browsersetup.test.BrowserSetup;
import org.testng.*;
import org.testng.annotations.*;
import org.testng.annotations.Test;

@SuppressWarnings("unused")
public class sample2 extends BrowserSetup{
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();

@BeforeClass
public void setUp() throws Exception {
driver = new OperaDriver();
baseUrl = "http://www.ebay.com/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
System.out.println("Browser = " + driver);
System.out.println("Base URL = " + baseUrl);
}

@Test
public void testUntitled() throws Exception {
driver.get(baseUrl + "/");
Thread.sleep(10000);
WebElement element = driver.findElement(By.name("_sacat"));
Select dd= new Select(element);
List<WebElement> allOptions= dd.getOptions();

//To go through the list, we can use an Iterator.
//Iterator should be of the same type as the List
//which is WebElement in this case.

Iterator<WebElement> it = allOptions.iterator();
//Using while loop, we can iterate till the List has
//a next WebElement [hasNext() is true]
//number of items in the list
System.out.println(allOptions.size());

while(it.hasNext()){
//When you say it.next(), it points to a particular
//WebElement in the List.
WebElement el = it.next();
//Check for the required element by Text and click it
if(el.getText().equals("mango")){
System.out.println(el.getAttribute("value"));
el.click();
}
}

@AfterClass
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}

private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}

private boolean isAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {
return false;
}
}

private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
}

我不知道哪里错了,指导我哪里错了

提前致谢

最佳答案

参见 org.openqa.jetty.html.List 的 javadoc:http://www.jarvana.com/jarvana/view/org/seleniumhq/selenium/selenium-server/2.0b1/selenium-server-2.0b1-javadoc.jar!/org/openqa/jetty/html/List.html

java.util.List 之一:http://docs.oracle.com/javase/7/docs/api/java/util/List.html

您使用的不支持泛型(如错误所述)。

您的问题似乎是以下导入:

import org.openqa.jetty.html.List;

尝试将其替换为:

import java.util.List;

有关更多想法,请参阅类似问题:The type Collection is not generic; it cannot be parameterized with arguments <? extends E>

关于java - Selenium 网络驱动程序 : <WebElement> Iterator cannot be resolved to a type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17668329/

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