我正在尝试使用 selenium 查找网页的损坏图像/链接。我正在使用以下代码。问题是在 Eclipse 中e.getText()
显示错误为“方法 getText 未定义类型 webelement”所以我也进行了类型转换,但它仍然显示新对象类型的相同错误。代码如下,
List<WebElement> linkElements = (List<WebElement>) driver.findElements(By.tagName("a"));
String[] linkTexts = new String[linkElements.size()];
int i = 0;
for (WebElement e : linkElements) {
linkTexts[i] = e.getText();
i++;
}
我在这里错过了什么吗?
更新......这是我的进口,
import java.io.IOException;
import java.net.URI;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;
除了这个,我还需要导入任何特定的类吗?