3

我的问题简介

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

测试配置

  • 火狐浏览器
  • 日蚀靛蓝
  • 硒网络驱动程序 2

我测试的场景

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

我的错误

java.lang.Error: 未解决的编译问题:List 类型不是通用的;它不能用参数进行参数化迭代器不能被解析为一个类型

我的代码

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

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

提前致谢

4

1 回答 1

4

请参阅 javadocs org.openqa.jetty.html.Listhttp ://www.jarvana.com/jarvana/view/org/seleniumhq/selenium/selenium-server/2.0b1/selenium-server-2.0b1-javadoc.jar!/org/openqa/jetty/ html/列表.html

和其中之一java.util.Listhttp ://docs.oracle.com/javase/7/docs/api/java/util/List.html

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

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

import org.openqa.jetty.html.List;

尝试将其替换为:

import java.util.List;

有关更多想法,请参见类似问题:Collection 类型不是通用的;它不能用参数参数化 <? 扩展 E>

于 2013-07-16T05:37:27.677 回答