尝试使用selenium web驱动程序获取水银之旅主页中的所有链接时出现异常

时间:2014-09-18 13:25:35

标签: java selenium webdriver web-scraping

System.setProperty("Webdriver.chrome.driver", "F:/shiva testing/chromedriver.exe");
    //System.out.println("hai");

    WebDriver driver=new ChromeDriver();
    driver.get("http://newtours.demoaut.com/");
    String underConsTitle= "Under Construction : Mercury Tours";
    //driver.get("http://www.google.co.in/");
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    java.util.List<WebElement>linkElements =driver.findElements(By.tagName("a"));
    String[]linkText=new String[linkElements.size()];
    int i=0;
    for(WebElement e:linkElements)
    {
    linkText[i]= e.getText();
    i++;

    }
    for(String t: linkText)
    {
        ((WebElement) driver.findElements(By.linkText(t))).click();
        if(driver.getTitle().equals(underConsTitle))

        //if (driver.getTitle().equals(underConsTitle))
        {
            System.out.println("\"" +t+"\"" +"is under construction");

        }   
        else
        {
            System.out.println("\"" +t+"\"" +"working");
        }
        driver.navigate().back();
The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
    at com.google.common.base.Preconditions.checkState(Preconditions.java:177)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:105)
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:89)
    at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:117)
    at mypackage.Getalllinks.main(Getalllinks.java:22)

2 个答案:

答案 0 :(得分:1)

你的问题在第1行,它应该是:

System.setProperty("webdriver.chrome.driver", "F:/shiva testing/chromedriver.exe");

请注意“webdriver”的大小写!

答案 1 :(得分:0)

您的问题是webdriver.chrome.driver密钥区分大小写,不仅是此密钥,而且所有密钥都区分大小写。