- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我的问题简述:
现在通过我的 selenium 网络驱动程序,我正在测试列表框中的元素列表,在使用以下代码时出现错误
测试配置:
我测试的场景:
我的错误:
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/
我是一名优秀的程序员,十分优秀!