由于"未解决的编译问题,我无法使用Web驱动程序运行Java程序:all_links_webpage无法解析"。谁能指出我哪里出错?
package lightart_TC;
import java.util.List;
public class light {
private static int linkscount;
public static void main(String[] args) throws InterruptedException {
int size,List;
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
List <WebElement> linksize = driver.findElements(By.tagName("a"));
linkscount = linksize.size();
System.out.println("no. of links");
Links = new string[linkscount];
System.out.println("list of links available");
for (int i = 0; i < linkscount; i++)
{
links[i]= linksize.get(i).getAttribute("href");
System.out.println(all_links_webpage.get(i).getattribute("href"));
}
for (int i = 0; i < linkscount; i++)
{
driver.navigate().to(links[i]);
Thread.sleep(3000);
}
}}
错误:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
all_links_webpage cannot be resolved
答案 0 :(得分:1)
w
中的WebElement
代码很小。
使用此:
List<WebElement> linksize
导入包:
import java.util.List;
import org.openqa.selenium.WebElement;
以下代码适用于我:
public class light {
private static int linkscount;
public static void main(String[] args) throws InterruptedException {
int size,List;
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://www.changning.sh.cn/jact/front/front_mailpublist.action?sysid=9");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
List <WebElement> linksize = driver.findElements(By.tagName("a"));
linkscount = linksize.size();
System.out.println("no. of links");
}
}